【问题标题】:Sending email using smtp on gmail [duplicate]在gmail上使用smtp发送电子邮件[重复]
【发布时间】:2016-02-29 06:54:24
【问题描述】:

我正在尝试使用 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 需要身份验证

【问题讨论】:

  • 当您尝试从某些应用程序登录时,Google 可能会阻止某些应用程序或设备的登录尝试。查看此答案以获取更多详细信息:stackoverflow.com/a/32475872/2946329

标签: c# email smtp gmail


【解决方案1】:
猜你喜欢
  • 2011-08-18
  • 2014-12-24
  • 2011-08-01
  • 2017-06-21
  • 1970-01-01
  • 2016-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多