0 votes

Hi in the last 2 weeks a get an SSPI failed message every x hours. I am fetching emails all the time with a timer and the inner exception is :

The message received was unexpected or badly formatted

I use gmail as mail server to read mails do you have any ideas of what is causing the problem?

by

1 Answer

0 votes

There is a chance that one of the Gmail servers is configured in a different way. For example it allows specific version of TLS and your client machine is not supporting it.

You can also try forcing specific protocol version:

using (Imap client = new Imap())
{
    // this forces TLS 1.2:
    client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12;

    client.ConnectSSL("imap.gmail.com");
    client.UseBestLogin("user@gmail.com", "password");

    client.SelectInbox();
    foreach(long uid in client.SearchFlag(Flag.Unseen))
    {
        string eml = client.GetMessageByUID(uid);
        IMail email = new MailBuilder().CreateFromEml(eml);
        Console.WriteLine(email.Subject);
    }
    client.Close();
}
by (301k points)
thanks for your reply. i did what you described but the problem persists. i use windows 10 actually. do you think i should apply the fix or something else?
Is it reproducible? Does it happen for specific account?

What is the exact error message and stack trace?

Does forcing SslProtocols.Tls11 or SslProtocols.Tls12 or SslProtocols.SSL3 help?

Since this happened after upgrade to Windows 10, maybe you should contact Microsoft support.
...