我尝试使用我的Google Apps帐户发送电子邮件, 我一直收到这个错误:
SMTP服务器需要安全连接,或者客户端未经过身份验证。服务器响应为:5.5.1需要身份验证
当我使用普通的Gmail帐户尝试相同的代码时,这有效。
var msg = new MailMessage();
msg.IsBodyHtml = true;
msg.Subject = "subject here";
msg.Body = "body here";
msg.To.Add("email adress here");
var client = new SmtpClient();
client.EnableSsl = true;
client.Send(msg);
答案 0 :(得分:3)
您需要在端口587上连接到Gmail的SMTP服务器并指定SSL连接
http://support.google.com/mail/bin/answer.py?hl=en&answer=13287
答案 1 :(得分:0)
您不发送凭据,也不指定SMTP服务的SSL端口
var msg = new MailMessage();
msg.IsBodyHtml = true;
msg.Subject = "subject here";
msg.Body = "body here";
msg.To.Add("email adress here");
var client = new SmtpClient();
client.EnableSsl = true;
client.Port = 465;
client.Host = "smtp.gmail.com";
client.Credentials = new NetworkCredential("xxxxxx@gmail.com", "mypassword");
client.Send(msg)