5.7.0 Must issue a STARTTLS command first

时光毁灭记忆、已成空白 提交于 2019-12-08 11:20:54

问题


I'm trying to send email through C#. Although I beleive I've done everything right, it still throws this exception :

"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"

At first I thought, it could be a zone/ip/region problem... But when i logged into gmail, there wasn't any warning of that. And to be sure, i've uploaded a file to a website to check from there, still the error was thrown.

Than I've tried changing the port to 465. It didn't work either.

I've first tried with accounts that are managed by a Google Apps account. So I thought it could be it, but it wasn't either...

I'm truly out of ideas right now.

Any of you have an idea ?

Here is the example code :

   SmtpClient sm = new SmtpClient("smtp.gmail.com",587);

        sm.Credentials = new NetworkCredential("blabla@gmail.com","**");
        sm.UseDefaultCredentials = false;
        sm.EnableSsl = true;
        sm.DeliveryMethod = SmtpDeliveryMethod.Network;
        sm.Send("blabla@gmail.com","blabla2@tr3reklam.com","Test","Test");

** Note ** I've checked the account name and password, they both are right.


回答1:


"Access for less secure apps" must be enabled for the Gmail account used by the NetworkCredential using Google's settings page.




回答2:


It was caused by 2-Step Verification after all !

It is odd, but without turning on "Allow users to be able to turn on 2-Step verification on" option set to true, I couldn't send any mails.

2-Step verification is still off for the accounts but, probably allowing users to choose for themselves make some security settings in the background.

I couldn't find any documentation about this but I can send now...




回答3:


Put the code sm.UseDefaultCredentials = false; before sm.Credentials = ...



来源:https://stackoverflow.com/questions/28664320/5-7-0-must-issue-a-starttls-command-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!