我尝试发送邮件时出现此错误
SMTP服务器需要安全连接,或者客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。
了解更多信息
这是我的代码:
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(MySMTPClient);
mail.From = new MailAddress(MySendingAddress);
mail.To.Add(recieverAddress);
mail.Subject = subject;
mail.Body = content;
SmtpServer.Port = MyPort;
SmtpServer.Credentials = new System.Net.NetworkCredential(MySendingAddress, MyPassword);//(MySendingAddress, MyPassword);
SmtpServer.EnableSsl = true;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Send(mail);
答案 0 :(得分:0)
尝试使用此代码邮寄:
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(Username);
mail.To.Add(emailTo);
mail.Subject = Subject;
mail.Body = Body;
SmtpServer.Port = 587; // Also Add the port number to send it, its default for Gmail
SmtpServer.Credentials = new System.Net.NetworkCredential(Username, Password);
SmtpServer.EnableSsl = true;
SmtpServer.Timeout = 20000; // Add Timeout property, it is optional part
SmtpServer.Send(mail);
让我知道它是否有效。