【问题标题】:ASP.Net C# Sending E-Mail SMTP IssueASP.Net C# 发送电子邮件 SMTP 问题
【发布时间】:2016-02-03 04:47:36
【问题描述】:

大家好,我正在尝试从我的 ASP.Net Web 应用程序发送一封电子邮件,我正在我的 Web.config 上使用它:

<system.net>
<mailSettings>
  <smtp>
    <network host="smtp.gmail.com" userName="myemail" password="mypass" port="587" enableSsl="true" />
  </smtp>
</mailSettings>

一切都正确,但我收到此错误消息:

System.Net.Mail.SmtpException: 
The SMTP server requires a secure connection or not done client authentication. 
The server response was: 5.5.1 Authentication Required. 
Learn more at at System.Net.Mail.MailCommand.CheckResponse 
(SmtpStatusCode statusCode, String response) in System.Net.Mail.MailCommand.Send 
(SmtpConnection conn, Byte [] command, MailAddress from, Boolean allowUnicode) 
in System.Net. Mail.SmtpTransport.SendMail (MailAddress sender, MailAddressCollection 
recipients, String deliveryNotify, Boolean allowUnicode, 
SmtpFailedRecipientException & exception) in System.Net.Mail.SmtpClient.Send 
(MailMessage message) at Account_Registration.Registration () 
in c: \ Users \ User \ Documents \ Visual Studio 2013 \ WebSites \ 
MyWebsite \ Account \ Registration.aspx.cs: line 177

正如您在我的 Web.config 文件中看到的那样,我已启用 Ssl,所以我仍然收到此错误,并且我的帐户收到一封电子邮件,表明有人试图在未经许可的情况下使用我的电子邮件。有人可以帮忙吗?

【问题讨论】:

标签: c# asp.net email smtp


【解决方案1】:

<appSettings> <add key="EmailHost" value="smtp.gmail.com" /> <add key="EmailPort" value="587" /> <add key="EmailUsername" value="myemail" /> <add key="EmailPassword" value="mypass" />

        var mailClient = new SmtpClient(
            Convert.ToString(ConfigurationManager.AppSettings["EmailHost"]),
            Convert.ToInt32(ConfigurationManager.AppSettings["EmailPort"]))
        {
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials =
                new NetworkCredential(
                    Convert.ToString(ConfigurationManager.AppSettings["EmailUsername"]),
                    Convert.ToString(ConfigurationManager.AppSettings["EmailPassword"]))
            //EnableSsl = true
        };

        mailClient.SendCompleted += (s, e) => {
            mailClient.Dispose();
        };
        return mailClient.SendMailAsync(email);

【讨论】:

  • 不,不工作我什至没有收到错误消息,但感谢您的尝试:)
猜你喜欢
  • 1970-01-01
  • 2016-04-17
  • 2014-04-25
  • 2016-08-30
  • 2019-01-23
  • 2019-05-15
  • 2013-04-05
  • 2016-04-20
  • 1970-01-01
相关资源
最近更新 更多