Number of unread messages

Discussion for developers using MailEnable.
Post Reply
arno
Posts: 1
Joined: Wed Apr 20, 2011 10:58 am

Number of unread messages

Post by arno »

Hi
This seems pretty straightforward but I can't find a simple solution: I'm trying to get the number of unread messages in a mailbox from an aspx page.
I can of course loop through the store items and check for new messages using the PR_ME_READ flag but this can be a very long process if there's a large number or messages in the box.
isn't there a simpler way to count unread messages?

i found this on the forum, which is exactly what i'm looking for, unfortunately the MEwebMail.MailMessages class doesn't seem to be supported anymore, is that the case?

Dim oMessages As New MEWebMail.MailMessages
oMessages = CreateObject("MEWebMail.MailMessages")
oMessages.PostOffice = "PO"
oMessages.UserName = "Demo"
response.write(oMessages.GetNewMessageCount())
oMessages = Nothing

Thanks for your help

MailEnable
Site Admin
Posts: 4441
Joined: Tue Jun 25, 2002 3:03 am
Location: Melbourne, Victoria Australia

Re: Number of unread messages

Post by MailEnable »

Unfortunately, the best way to do it is not actually documented in the .Net API guide (So I will post it here).

Firstly, you need to define this struct:

Code: Select all

       
Private Structure IFOLDERSTATUSTYPE
            Public SystemFlag As Integer
            Public NumDeleted As Integer
            Public NumDraft As Integer
            Public NumAnswered As Integer
            Public NumFlagged As Integer
            Public FirstUnSeen As Integer
            Public NumMessages As Integer
            Public NumSeen As Integer
            Public NumNew As Integer
            Public NumRecentMessages As Integer
            Public NumNewMessages As Integer
            Public LastUID As Integer
End Structure
You need to declare this entrypoint into MEAISP.DLL

Code: Select all

Private Declare Function GetCachedStatus Lib "MEAISP.DLL" (ByVal Postoffice As String, ByVal Mailbox As String, ByVal Folder As String, ByRef lpFolderStatus As IFOLDERSTATUSTYPE) As Integer
You can then call it like this (untested):

Code: Select all

Dim FolderStatus As IFOLDERSTATUSTYPE
Dim iResult = GetCachedStatus("PostofficeName","MailboxName","/Inbox",FolderStatus)
if (iResult=1) 
            Response.Write FolderStatus.NumMessages-FolderStatus.NumSeen
end if
If this does not do what you want, then perhaps post and I will run it up and validate it.
Regards, Andrew

Post Reply