我正在尝试使用google提供的smtp向用户发送确认电子邮件,并在我的本地计算机上进行测试。我已经编写了代码并提供了设置。
SmtpClient client = SiteUtilites.GetMailClient();
MailAddress sender = new MailAddress(coreEmail, coreDisplayName);
MailAddress receiver = new MailAddress(model.EmailAddress, model.Firstname + " " +model.Lastname);
MailAddressCollection collection = new MailAddressCollection();
MailMessage mailMessage = new MailMessage(sender, receiver);
mailMessage.IsBodyHtml = true;
mailMessage.Body = "Hello";
client.Send(mailMessage);
这是我在下面的设置
String smtpServer = ConfigurationManager.AppSettings["smtpServer"];
String smtpUsername = ConfigurationManager.AppSettings["smtpUsername"];
String smtpPassword = ConfigurationManager.AppSettings["smtpPassword"];
String smtpPort = ConfigurationManager.AppSettings["smtpPort"];
SmtpClient sc = new SmtpClient(smtpServer);
NetworkCredential nc = new NetworkCredential(smtpUsername, smtpPassword);
sc.UseDefaultCredentials = false;
sc.Credentials = nc;
sc.EnableSsl = true;
sc.Port = 587;
我是否需要使用https运行我的网站?我只想在本地机器上测试我的脚本。
这是它给我的错误
SMTP服务器需要安全连接,或者客户端未经过身份验证。服务器响应为:5.5.1需要身份验证
答案 0 :(得分:0)