+1 vote

Hi,I'm trying to get imap email from yahoo. Development platform is mac os, asp.net core. And i've got this error when trying to connect.

Unhandled Exception: Limilabs.Client.ServerException:
Authenticate as SSL client failed. You might be connecting to non SSL port.
---> System.NotSupportedException: The requested security protocol is not supported. at
System.Net.SecurityProtocol.ThrowOnNotAllowed(SslProtocols protocols,
Boolean allowNone) at
System.Net.Security.SslStream.AuthenticateAsClient(String targetHost,
X509CertificateCollection clientCertificates, SslProtocols
enabledSslProtocols, Boolean checkCertificateRevocation)

Here's my code:

using (Imap imap = new Imap())
{
     imap.SendTimeout = TimeSpan.FromMinutes(1);
     imap.ReceiveTimeout = TimeSpan.FromMinutes(1);

     // imap.SSLConfiguration.EnabledSslProtocols = SslProtocols.Ssl3;
     imap.ConnectSSL("imap.mail.yahoo.com", 993);

     imap.Login("myloginm@yahoo.com", "mypass");

     imap.SelectInbox();

     List<long> uids = imap.Search(Flag.Unseen);
     foreach (long uid in uids)
     {
         IMail email = new MailBuilder()
             .CreateFromEml(imap.GetMessageByUID(uid));

         Console.WriteLine(email.Subject);
     }
     imap.Close();
}

if i try to change ssl version it can't quth because default security level not allowed old ssl version. Changing security setting on yahoo email is not an option because i have thousands emails and i need work with them without changing security settings for all accounts.

by (360 points)

1 Answer

+1 vote

Please try using TLS 1.2:

imap.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12

I just checked to be sure and Yahoo supports following TLS versions:
TLS 1.2, TLS 1.1, TLS 1.0.

by (301k points)
As I said it isn't working.
In this case I've got error Unhandled Exception: Limilabs.Client.IMAP.ImapResponseException: [AUTHENTICATIONFAILED] LOGIN Invalid credentials
   at  ​ .  (ImapResponse response)
   at  ​ . (ImapResponse response)
   at Limilabs.Client.IMAP.Imap. ​(String user, String password)

And also I  got message from yahoo with text that said that you are using old app that isn't  respond modern security requirement, its about ssl version. Because tls12 is deprecated. Of course i can change security setting in account, but that is not an option, because i have a lot of emails. The same thing I have with gmail accounts. If you want i can provide my few account for testing purpose.
1.
This is completely different error. It says "Invalid credentials".

2.
TLS 1.2 is the most recent SSL/TLS version: https://en.wikipedia.org/wiki/Transport_Layer_Security#TLS_1.2
TLS 1.2 is not deprecated, you must have read the email incorrectly.

3.
I'm not sure what Yahoo policy is, however, it might want you to use OAuth, which might or might not be a good solution in your case.

You can also generate third-party app password (note that two-step verification must be anabled):
https://help.yahoo.com/kb/sln15241.html

Or turn on "Allow apps that use less secure sign in" in "Account security" settings.
Could you write your email address , I will send credential data to you. And you will see. I can login with web interface of yahoo, but can't do this from code. Maybe you can help me to figure out hot to fix this behavior and where exactly the issue.
You can find our email address in the footer page, but there is nothing to test here.

Your options are clear:
- Allow apps that use less secure sign in.
- Use OAuth
- Use third-party app passwords

The term "less secure apps" is used only because such applications need to be provided with account's primary password. It doesn't refer to the TLS/SSL version you are using, or TLS 1.2 being deprecated (It's not. All banking sites use TLS 1.2).

You can find more detailed explanation here:
https://www.limilabs.com/blog/enable-imap-in-gmail

With OAuth you need to obtain OAuth access token and then use LoginOAUTH2 method:
imap.LoginOAUTH2(user, accessToken);

You can find OAuth 2.0 Gmail samples here:
https://www.limilabs.com/mail/samples#imap-gmail-oauth2
You're right. I had to enable third party app inside account. Do you know any way to do this procedure on all our yahoo accounts?Is it possible to do programmatically?
I have no idea.

In Google Apps, domain administrator can enable/disable this for all accounts within a domain.
...