// send Email
string toEmailAddress = dt.Rows[0][4].ToString();
string Username = dt.Rows[0][1].ToString();
string EmailBody = "Hi "+Username+ "<br/> click the link below to reset your password<br/> http://localhost:51583/RecoveryPass.aspx?Uid="+myGUID;
MailMessage PassRecMail = new MailMessage("youremail@gmail.com",toEmailAddress);
PassRecMail.Body = EmailBody;
PassRecMail.IsBodyHtml = true;
PassRecMail.Subject = "Reset Password";
SmtpClient SMTP = new SmtpClient();
SMTP.Port = 587;
SMTP.Host = "smtp.gmail.com";
SMTP.EnableSsl = true;
SMTP.UseDefaultCredentials = false;
SMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
SMTP.Credentials = new NetworkCredential()
{
UserName= "youremail@gmail.com",
Password= "yourGmailPassword"
};
SMTP.UseDefaultCredentials = false;
SMTP.Send(PassRecMail);
我收到此错误:
SMTP服务器需要安全连接,否则客户端不需要 认证。服务器响应为:5.5.1需要身份验证。 在线SMTP.Send(PassRecMail);
我已经开启谷歌较少的安全性,然后我也收到此错误。 我该如何解决?
答案 0 :(得分:1)
1,你将定义.......
使用System.Net.Mail;
使用System.Data.SqlClient;
使用System.Data;
使用System.Net;
使用System.Drawing;
然后我们可以创建一个新的gmail id(我认为最好)然后.......
SmtpClient smtpClient = new SmtpClient(“smtp.gmail.com”,587);
smtpClient.Credentials = new System.Net.NetworkCredential()
{
UserName = "shopify580@gmail.com",
Password = "********"
};
smtpClient.EnableSsl = true;
smtpClient.Send(mailMessage);