0
我使用下面的代碼來發送email.when我正在特林發送郵件我收到錯誤消息錯誤:SMTP服務器需要安全連接或客戶端未通過身份驗證。服務器響應爲:5.5.1需要驗證
MailMessage mail = new MailMessage(from.txt, to.txt, subject, body);
SmtpClient clint = new SmtpClient();
//for determile email smtp...
string x = from.txt;
int startIndex = x.IndexOf('@');
int endIndex = x.LastIndexOf('.');
int length = endIndex - startIndex;
string xx = x.Substring(startIndex + 1, length - 1);
if (xx == "gmail" || xx == "Gmail")
{
clint.Host = "smtp.gmail.com";
clint.Port = 587;
clint.EnableSsl = true;
}
if (xx == "Hotmail" || xx == "hotmail" || xx == "live" || xx == "Live")
{
clint.Host = "smtp.live.com";
clint.Port = 587;
clint.EnableSsl = true;
}
if (xx == "yahoo" || xx == "Yahoo")
{
clint.Host = "smtp.mail.yahoo.com";
clint.Port = 465;
clint.EnableSsl = true;
}
clint.Credentials = new System.Net.NetworkCredential(username, password);
clint.DeliveryMethod = SmtpDeliveryMethod.Network;
clint.UseDefaultCredentials = false;
clint.Send(mail);
MetroMessageBox.Show(this, "Email Successfully Send", "Success",
MessageBoxButtons.OK, MessageBoxIcon.Information);
以及任何文件怎麼能把這個電子郵件
用戶名應該是完整的電子郵件地址。你是? –
啓用雙因素身份驗證(又稱爲兩步驗證),然後生成應用程序專用密碼。使用新生成的密碼通過SMTP進行身份驗證。 –
爲什麼不使用服務提供商允許您使用的SMTP服務器並使其更容易? –