0 votes

Not able to pick mails from inbox of outlook account but same is working fine for gmail account after changing port, server address and credentials.

On using outlook it gives "Tried to read a line. Only '' received. Please make sure that antivirus and firewall software are disabled or configured correctly" Exception on calling imap.Search() method.

But no such error for gmail account.


[Edited]

Hi Details are following-
Server address- outlook.office365.com
port no- 993

Exception trace is following

Exception occured Tried to read a line. Only '' received. Please make sure that antivirus and firewall software are disabled or configured correctly. | at    . () at    . (MemoryStream memory) at    . () at Limilabs.Client.IMAP.ImapResponse. (Stream reader) at Limilabs.Client.IMAP.Imap.  (ImapResponse response) at Limilabs.Client.IMAP.FluentSearch.GetList() at Limilabs.Client.IMAP.Imap.Search(ICriterion criterion)

code is following

public ParseEmail(
    string sImapHost, 
    int nImapPort, 
    bool ssl, 
    string sImapUser, 
    string sImapPassword)
{
     imap.SSLConfiguration.EnabledSslProtocols =     
        System.Security.Authentication.SslProtocols.Tls12;

    imap.ConnectSSL(sImapHost, nImapPort);
    imap.UseBestLogin(sImapUser, sImapPassword);
    imap.SelectInbox();

    SimpleImapQuery query = new SimpleImapQuery();
    query.Subject = SubjectLine;
    List<long> MessageIds = imap.Search(query);

The search method at the end is giving mentioned exception.

by (200 points)
edited by
You need to provide some more details.

How does your code look like?
What is the exception stack trace?
What is the server address you connect to?
Does it work if you exchange Search() with GetAll() or Search(Flag.Unseen)?

Turning logging would be helpful as well:
https://www.limilabs.com/blog/logging-in-mail-dll

"Tried to read a line. Only '' received." is usually a network problem:
https://www.limilabs.com/blog/tried-to-read-a-line-only-received
Hi Details are following-
Server address- outlook.office365.com
port no- 993
Exception trace is following--
 Exception occured Tried to read a line. Only '' received. Please make sure that antivirus and firewall software are disabled or configured correctly. | at    . () at    . (MemoryStream memory) at    . () at Limilabs.Client.IMAP.ImapResponse. (Stream reader) at Limilabs.Client.IMAP.Imap.  (ImapResponse response) at Limilabs.Client.IMAP.FluentSearch.GetList() at Limilabs.Client.IMAP.Imap.Search(ICriterion criterion)

code is following

public ParseEmail(string sImapHost, int nImapPort, bool ssl, string sImapUser, string sImapPassword)
        {
                imap.SSLConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12;
                 imap.ConnectSSL(sImapHost, nImapPort);
                 imap.UseBestLogin(sImapUser, sImapPassword);
                imap.SelectInbox();

        }

Dictionary<string, string> MessageList = new Dictionary<string, string>();
            SimpleImapQuery query = new SimpleImapQuery();
            query.Subject = SubjectLine;
            List<long> MessageIds = imap.Search(query);

The search method at the end is giving mentioned exception.

Also GetAll() is working fine.

1 Answer

0 votes

[Edit]

Seeing from the logs how big your mailbox is (634'037 emails), my assumption is the server is not able to search through the mailbox without timing out.

You can limit your serach -or- extend the timeout.


All queries are executed by the IMAP server.

Mail.dll simply issues a query and receives results. In this case it is a very simple query, and server shouldn't have any problems executing it.

However it looks like server is note returning anything within default timeout. Please note that this indicates a server side issue.

Here are a couple of things you may try:

1.
If your mailbox is really big try increasing read timeout:

imap.ReceiveTimeout = TimeSpan.FromSeconds(60);

2.
Does using a Expression.Subject work:

client.Search(Expression.Subject(SubjectLine));

3.
Does using a string that for sure doesn't exist in the mailbox work:

client.Search(Expression.Subject("ZeroResultSubjectSearch"));

4.
Does using a GetAll() or Search(Flag.Unseen) work?

5.
Are you using some non-letter characters in your search (e.g. quotes, apostrophes)?

Mail.dll should encode those properly, but maybe the server is not following the spec correctly.

6.
Please turn on logging:
https://www.limilabs.com/blog/logging-in-mail-dll

by (297k points)
edited by
1. Increased timeout, but didn't work
2. using a string that for sure doesn't exist in the mailbox also didn't work.
3. GetAll() and Search(Flag.Unseen) are working fine
4. No, I am not using any non-letter characters in search. subject lin is  "Schedule Change for PNR"
5. on Turning on Logging following is bein shown

C: 407C0004 LIST "" ""
S: * LIST (\Noselect \HasChildren) "/" ""
S: 407C0004 OK LIST completed.
C: 407C0005 SELECT INBOX
S: * 634037 EXISTS
: * 6 RECENT
S: * FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
S: * OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
S: * OK [UNSEEN 471656] Is the first unseen message
* OK [UIDVALIDITY 14] UIDVALIDITY value
S: * OK [UIDNEXT 1923361] The next unique identifier value
S: 407C0005 OK [READ-WRITE] SELECT completed.
C: 407C0006 UID SEARCH SUBJECT "Schedule Change for PNR"
The thread 0x4d8c has exited with code 0 (0x0).
Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
Exception thrown: 'System.IO.IOException' in System.dll
Exception thrown: 'System.IO.IOException' in System.dll
Exception thrown: 'System.Exception' in Mail.dll
Exception thrown: 'Limilabs.Client.ServerException' in Mail.dll
Exception thrown: 'Limilabs.Client.ServerException' in Mail.dll
The log looks correct. The query generated by Mail.dll is certainly a valid one.

Seeing how big is your mailbox (634'037 emails), my assumption is the server is not able to search it without timing out.

Does limiting the results and simplifying a subject search a bit help:

List<long> uids = client.Search(
    Expression.And(
        Expression.Since(new DateTime(2020,05,01)),
        Expression.Subject("Schedule")));
...