问题
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