No Message Found

Topics: Help requests
Feb 8, 2014 at 7:15 AM
Edited Feb 8, 2014 at 7:16 AM
Hi,

It appears I'm not able to access the messages in my inbox from vb.net.

When I run this:
Dim msgCount As Integer
msgCount = client.Folders.Inbox.Messages.Count
The project seems to process for a short time as if it's counting messages, but msgCount is returned as 0 every time I run it.

Here's what I have so far:
Public Function getMsg() 

   Dim client As New ImapClient("imap.gmail.com", True)
   Dim msg As ImapX.Message
   Dim msgCount As Integer

   If imapSvr.Connect() Then
      If imapSvr.Login(username, password) Then
         msgcount = client.Folders.Inbox.Messages.Count
      End If
   End If
End Function
Connecting and logging in seem to function correctly. The messages are the only thing I'm having issue with.

I'm running .NET framework v 4.5 with the 4.5 version of imapx.dll v 2.0.0.15

Any suggestions on what I could be doing wrong?

Thanks!
Coordinator
Feb 8, 2014 at 10:31 AM
Hi Jacob_P,

by default, the Folder.Messages collection is not being filled. If you want to let the client download the messages automatically, configure the client do do this:
Dim client As New ImapClient("imap.gmail.com", True)
client.Behavior.AutoPopulateFolderMessages = True
However, it's often better to make a call to Folder.Messages.Download instead or use Folder.Search.

For more details take a look at the documentation. Especially the Searching and downloading messages section is interesting.

Greets,

Pavel
Feb 8, 2014 at 8:31 PM
Thanks for the quick reply Pavel,

I set AutoPopulateFolderMessages = True and tried getting the message count again, but the console then spun for a while and never returned a value or error.

I tried the search method:
imapSvr.Behavior.AutoPopulateFolderMessages = True
Dim msg As ImapX.Message
If imapSvr.Connect() Then
   If imapSvr.Login(username, password) Then
      msg = imapSvr.Folders.Inbox.Search("From<example@mail.com>")
   end if
end if
But VB returns the debugging error "Value of type '1-dimensional array of ImapX.Message' cannot be converted to 'ImapX.Message'." Which doesn't make sense as they appear to be the same type, even according to the error message.

And the download method:
imapSvr.Behavior.AutoPopulateFolderMessages = True
Dim msg As ImapX.Message
If imapSvr.Connect() Then
   If imapSvr.Login(username, password) Then
      msg = imapSvr.Folders.Inbox.Messages.Download("From<example@mail.com>")
   end if
end if
VB returns the debugging error "Expression does not produce a value" highlighting the section after "msg = ".

Starting to think I'm just stupid or am cursed to never get access to my emails. :P
Feb 8, 2014 at 8:41 PM
Edited Feb 8, 2014 at 8:42 PM
And the answer is: I'm stupid. Forgot to declare my Imap.Message as an array, obviously. Still trying to get the search query to work, but I'll get back to you. Sorry to waste your time with my newb mistake.
Coordinator
Feb 8, 2014 at 9:34 PM
Edited Feb 8, 2014 at 9:34 PM
Hi Jacob_P,

the search query is wrong, and a better approach here would be using the Folder.Search method instead of MessageCollection.Download. Here is the corrected version of your code:
Dim imapSvr As New ImapClient("imap.gmail.com", True)
imapSvr.Behavior.AutoPopulateFolderMessages = True

Dim msgs As ImapX.Message()
If imapSvr.Connect() Then
   If imapSvr.Login(username, password) Then
      msgs = imapSvr.Folders.Inbox.Search("FROM \"example@mail.com\"")
   End if
End if