这是我发送邮件的代码(测试代码):
//sending mail
var message = new System.Net.Mail.MailMessage();
message.From = new MailAddress("J2v@gmail.com");
message.To.Add(model.Mailag);
message.Subject = "Valdation d'inscription";
message.Body = "Votre inscription a été valide voici vos cordonne de conexion ID user : "+model.Idag+" Password : "+user.password;
var client = new System.Net.Mail.SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("", "")
};
client.Send(message);
当我尝试它时,我得到了这个错误:
SMTP 服务器需要安全连接,否则您未连接。服务器响应是:5.5.1 需要身份验证。了解更多信息
在这条线上:client.Send(message);