如何从c#发送电子邮件到Gmail
本文关键字:电子邮件 Gmail | 更新日期: 2023-09-27 17:50:48
protected void BtnSubmit_Click(object sender, EventArgs e)
{
GetAllUsersName U = new GetAllUsersName();
string Email = U.GetUSEREmail(TxtEmailPass.Text);
SmtpClient mySmtpClient = new SmtpClient("smtp.gmail.com", 587);
mySmtpClient.EnableSsl = true;
mySmtpClient.UseDefaultCredentials = false;
mySmtpClient.Credentials = new NetworkCredential("Projects@gmail.com", "Pro123456789");
mySmtpClient.EnableSsl = true;
MailMessage msg = new MailMessage("Projects@gmail.com", Email, "Password", "your password is:");
mySmtpClient.Send(msg);
}
这是我的代码,但是它一直告诉我:
SMTP服务器需要安全连接,或者客户端没有安全连接身份验证。服务器的响应是:5.5.1 Authentication Required.
您的代码看起来很好。如果这是一个新帐户,请确保您更改了密码-至少一次。Gmail可能在寻找你修改密码