Error on sending email using gmail. The SMTP server requires a secure connection or the client was not authenticated

余生长醉 提交于 2019-12-12 03:23:55

问题


Here is my code.

var smtp = new SmtpClient("smtp.gmail.com", 587)
        {

            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential("sender@gmail.com","123")
        };
        try
        {
            smtp.Send("sender@gmail.com", "receiver@gmail.com", "test", "testbody");
        }
        catch (SmtpException e)
        {
            ltrInfo.Text=e.Message;
        }

When I debug the code, I get the error "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required" Please can you tell me what's the wrong with the code above?


回答1:


Everything looks ok.

Here are 2 possible solutions

Get to your Gmail account's security settings and set permissions for "Less secure apps" to Enabled.

Check if there is not a "Suspicious login attempt" on the top of the page, if is there click to authorizing the access

take a look on this Tell me if works.



来源:https://stackoverflow.com/questions/28234478/error-on-sending-email-using-gmail-the-smtp-server-requires-a-secure-connection

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