【问题标题】:On server Getting exception The SMTP server requires a secure connection or the client was not authenticated在服务器上出现异常 SMTP 服务器需要安全连接或客户端未通过身份验证
【发布时间】:2014-05-08 03:12:15
【问题描述】:

我有一个发送邮件的代码。当我在本地主机上发送邮件时,邮件很容易发送,但是当我将代码上传到服务器时。我遇到了这个异常

   System.Net.Mail.SmtpException: The SMTP server requires a secure
connection or the client was not authenticated. The server response
was: 5.5.1 Authentication Required. Learn more at at
System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode,
String response) at System.Net.Mail.MailCommand.Send(SmtpConnection
conn, Byte[] command, MailAddress from, Boolean allowUnicode) at
System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,
MailAddressCollection recipients, String deliveryNotify, Boolean
allowUnicode, SmtpFailedRecipientException& exception) at
System.Net.Mail.SmtpClient.Send(MailMessage message) at
Admin_test.Page_Load(Object sender, EventArgs e) in
d:\hostingspaces\abd9009\ihmsgr.domainNames.net\wwwroot\info\test.aspx.cs:line
29

我的代码在我的本地机器和其他服务器上完美运行,但是 在您的服务器上不起作用是这样的:

  protected void Page_Load(object sender, EventArgs e)
    {
        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
        mail.To.Add("username@gmail.com");
        mail.From = new MailAddress("username@gmail.com", "Email
head", System.Text.Encoding.UTF8);
        mail.Subject = "This mail is send from asp.net application";
        mail.SubjectEncoding = System.Text.Encoding.UTF8;
        mail.Body = "This is Email Body Text";
        mail.BodyEncoding = System.Text.Encoding.UTF8;
        mail.IsBodyHtml = true;
        mail.Priority = MailPriority.High;
        SmtpClient client = new SmtpClient();
        client.Credentials = new
System.Net.NetworkCredential("username@gmail.com", "MyPassword");
        client.Port = 587;
        client.Host = "smtp.gmail.com";
        client.EnableSsl = true;
        try
        {
            client.Send(mail);
             }
        catch (Exception ex)
        {
            Response.Write(ex);
}
}

我正在使用服务器上的托管空间http://www.arvixe.com/请帮助

【问题讨论】:

  • 尽快删除并重新发布,代码中没有您的 GMAIL 用户名和密码!!!
  • 用虚拟用户名和密码修改了亲爱的
  • 您仍然可以在修订历史记录中看到您的密码,仅供参考。此时更改密码可能最容易。您应该学习如何使用wireshark 和telnet 实际调试smtp 流量,因为您可能还会遇到其他问题。
  • 我更改了密码

标签: c# asp.net .net email authentication


【解决方案1】:

试试这个。

1) EnableSSL true or false

2) 再次检查凭据

3) 有时某些 SMTP 服务器(主要用于公司)不允许外部访问或有单独的 IP 用于外部访问

4) 检查用户名是否应包含@Host.com 或不包含它

我希望其中一个对你有用。

【讨论】:

    【解决方案2】:

    试一试,我刚刚遇到了这个问题,但我的解决方案可能是不同的情况。 我的客户给了我他全新的 noreply@hisSite.com 的凭据,然后我尝试将它们用作凭据,然后我收到了这个错误,因为他至少有一次没有登录。我登录并成功了

    可能是这些事情之一可以帮助你

    1. 尝试登录您的帐户并更改密码并设置新密码(强密码)
    2. 尝试使用 mail.UseDefaultCredentials = false;

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 2011-05-28
      • 2019-01-28
      • 2017-12-02
      • 2012-03-06
      • 2015-11-26
      相关资源
      最近更新 更多