+1 vote

Before I decide to purchase Limilabs IMAP Mail library, I need to ensure it works.

I have been unable to successfully search through my email for words contained in the Subject field of my email stored on my provider.

I have tried various things, none of which seem to work.

The code I have written (VB.Net) follows. The search on Flag.all works fine, but if I place a text value in the form field "txtSubject"
the search does not find anything. Any ideas?

Using imap As New Imap
 imap.Connect(My.Settings.MailServer)  ' or ConnectSSL for SSL
 imap.UseBestLogin(My.Settings.UserName, My.Settings.Password)
 If txtSubject.Text.Trim.Length > 0 Then
  query.Subject = txtSubject.Text.Trim
  oList = imap.Search(query)
  oList = imap.Search((Flag.All))
 End If
 Dim lvi As ListViewItem = Nothing
 For Each uid As Long In oList
   Dim email As IMail = New _ 
   lvi = lvMail.Items.Add(uid.ToString.Trim)
   'set all columns to auto-resize
   'keep the listview scrolling during retrieval
   lvMail.TopItem = lvi
   lvMail.EnsureVisible(lvMail.Items.Count - 1)
   'allow outside processes to keep going (no hogging!)
End Using
by (460 points)
edited by

1 Answer

0 votes
Best answer

Consider instantiating query ad-hoc or using following expresion:using

oList = imap.Search(Expresion.Subject(txtSubject.Text.Trim))

Turn on logging ( https://www.limilabs.com/blog/logging-in-mail-dll ) to see the exact client-server communication.

Mail.dll only sends a query to the server, if it performs poor job of searching there's not much you or Mail.dll can do about it.

Remember that search is performed inside currently selected folder only.

Some servers (like Gmail for example) don't work with word parts.
Having a message with a subject: "this is an example", server won't return any results for searches like "exam" or "ample". Of course whole words work.

by (296k points)
selected by
Thank you for that, that seems to work fine.

Now I need to work out how to download a particular email from the host (I assume it is in EML format) and then convert it to MSG format for attachment to newly created emails via Outlook. As a help to others, I will create a seperate question for that. Thanks again.