gpt4 book ai didi

c# - 在 gmail 上使用 smtp 发送电子邮件

转载 作者:行者123 更新时间:2023-11-30 18:22:26 25 4
gpt4 key购买 nike

我正在尝试使用 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 运行吗?我只想在我的本地机器上测试我的脚本。

这是它给我的错误

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com