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

标签 c# email smtp gmail

我正在尝试使用 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

最佳答案

关于c# - 在 gmail 上使用 smtp 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33934207/

相关文章:

c# - 将 DWORD 从 C++ 返回到 C# (DllImport)

php - 如何在 PHP 中获取文件的内容类型?

ios - 应用内电子邮件发出嗖嗖声但不发送

java - 如何获得确切的字节数?

c# - 串联性能

c# - 如何正确处理系统托盘应用程序中的跨线程问题?

c# - 不使用 IP 识别机器

java - java mail api中的getInstance错误没有找到合适的方法

ssl - 我怎样才能使我的电子邮件像 PayPal 一样经过验证

windows - 当正文包含回车符和换行符时,如何使用 blat 从命令行发送电子邮件?