+1 vote

I'm making a modification in my program that uses Mail.dll. Here in company, we've changed from Gmail to Office365, and now I'm adapting the program. I've did the modifications, looks like the Mail.dll sucessiful connect, but when I perform the Imap.Search method, there's no return.

My Gmail code:

public MailRep(string host, int port, string login, string pass) {
    imap.ConnectSSL(host, port);
    imap.UseBestLogin(login, pass);

    // imap.SelectInbox(); <-- this is not needed

    CommonFolders common = new CommonFolders(imap.GetFolders());
    imap.Select(common.AllMail);


    List<long> idSelecao = imap.Search().Where(
        Expression.GmailRawSearch(criteria));
    ..
}

When I changed to Office365, after connect, he shows me NullPointerException in this command:

imap.Select(common.AllMail);

I've ripped off this lines from code, but the problem still remais in the Search method.

Can you help me please?

by

1 Answer

0 votes
 
Best answer

1.

There is no need to select INBOX if you plan to select different folder later:

// imap.SelectInbox(); // <- not needed

CommonFolders common = new CommonFolders(imap.GetFolders());
imap.Select(common.AllMail);

2.

NullPointerException in this command:
imap.Select(common.AllMail);

All Mail folder may be not present on the IMAP server you use.

For example Outlook.com has following folders only: Deleted, Drafts, Inbox, Junk, Notes, Outbox,Sent

3.

problem still remais in the Search method.

As the name suggest - Expression.GmailRawSearch - is a Gmail specific command. It is not exposed/implemented by any other IMAP server.

You need to use standard IMAP expressions for searching on other servers e.g.: to search by subject and body use the following code:

List<long> uids = imap.Search().Where(
    Expression.And(
        Expression.Subject("word")),
        Expression.Body("word")));

You can find more on searching in IMAP here:
https://www.limilabs.com/blog/how-to-search-imap-in-net

by (272k points)
...