Get imap unread email count in .net without bloated 3rd party libs

Ovephetnove

New Member
Background: We have an internal intranet system written in asp-classic and asp.net - the iis server doesnt have php installed (Seen some nifty solutions in php such as this but we cant really use these.) - we need to display to our users how many unread email they have in their imap mailbox. Their imap mailbox is hosted internally on a linux box running postfix and dovecot imap.My Question:How would one connect to Postfix mail system via Dovecot Imap in .net (vb or c#) and determine the number of unread items?What I've already tried:We used the Limilabs mail dll and the following:Imports System.Net.SecurityImports SystemImports Limilabs.MailImports Limilabs.Client.IMAPImports Limilabs.ClientFunction 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 UsingEnd FunctionPrivate 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 = FalseEnd SubHowever, whilst this works, this method is subject to reliance on a 3rd party, DLL will fail if licencing is not in place / up to date & is heavily bloated for what we need to do. We where just curious if this can be done in native .net code.
 
Back
Top