【发布时间】:2017-08-25 07:13:22
【问题描述】:
我在下面分享了我的代码,该代码在发送邮件时会引发错误。
var fromAddress = new MailAddress("sender@gmail.com", "Customer");
var toAddress = new MailAddress("reciever@gmail.com", "HR");
const string fromPassword = "senderpass";
const string subject = "Subject";
const string body = "Body";
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(fromAddress.Address, fromPassword);
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
这是更新后的代码,但这也不起作用
【问题讨论】:
-
您是否已将 Gmail 帐户配置为发送电子邮件?即在 GMail 上打开不太安全的应用程序
-
是的,gmail 上不太安全的应用已打开...
-
请所有朋友帮我解决这个问题....?