背景: asp-classicとasp.net で記述された内部イントラネット システムがあります- iisサーバーにはphpがインストールされていません (このような php の気の利いたソリューションをいくつか見ましたが、実際にはこれらを使用することはできません)。 imap メールボックスにある未読メールの数。彼らの imap メールボックスは、postfix と dovecot imap を実行している Linux ボックスで内部的にホストされています。
私の質問: .net (vb または c#) で Dovecot Imap を介して Postfix メール システムに接続し、未読アイテムの数を確認するにはどうすればよいですか?
私がすでに試したこと: Limilabs メール dllと以下 を使用しました。
Imports System.Net.Security
Imports System
Imports Limilabs.Mail
Imports Limilabs.Client.IMAP
Imports Limilabs.Client
Function RetrieveUnread(_server, _user, _password)
Using imap As New Limilabs.Client.IMAP.Imap
'#### Handler needed because of self signed certificates
RetrieveUnread = vbNull
AddHandler imap.ServerCertificateValidate, AddressOf ValidateCertificate
imap.ConnectSSL(_server)
Try
imap.Login(_user, _password)
Catch ex As Exception
RetrieveUnread = "Failed to login"
End Try
If CStr(RetrieveUnread) <> "Failed to login" Then
imap.SelectInbox()
Dim uids As List(Of Long) = imap.Search(Flag.Unseen) 'Find all unseen messages.
'Console.WriteLine("Number of unseen messages is: " & CStr(uids.Count))
RetrieveUnread = CStr(uids.Count)
End If
imap.Close()
End Using
End Function
Private Sub ValidateCertificate(ByVal sender As Object, ByVal e As ServerCertificateValidateEventArgs)
Const ignoredErrors As SslPolicyErrors = SslPolicyErrors.RemoteCertificateChainErrors Or SslPolicyErrors.RemoteCertificateNameMismatch ' name mismatch
Dim nameOnCertificate As String = e.Certificate.Subject
If (e.SslPolicyErrors And Not ignoredErrors) = SslPolicyErrors.None Then
e.IsValid = True
Return
End If
e.IsValid = False
End Sub
ただし、これは機能しますが、この方法はサードパーティに依存する可能性があります。ライセンスが適切でない場合、または最新の状態ではない場合、DLL は失敗します。これがネイティブの .net コードで実行できるかどうかに興味があります。