【问题标题】:"Authentication failed" error in sending Mail Asp.Net发送 Mail Asp.Net 时出现“身份验证失败”错误
【发布时间】:2016-01-09 15:12:14
【问题描述】:

搜索了很多网站也没有找到答案

我正在使用 VS2010(Framework 4.0) 和 SQL 2012,我们正在使用 Exchange 服务器....相同的邮件配置在 java 应用程序中工作,但在 c# 中不工作

按钮点击代码是:

    try
    {         
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "mail.myorganization.com"
        smtp.Port = "587";
        smtp.Credentials = new System.Net.NetworkCredential("abc@myorganization.com", "password");
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;        
            smtp.EnableSsl = true;
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("abc@myorganization.com");                  
        msg.To.Add(new MailAddress("receiver@something.com"));         
        msg.Subject = "Test";
        msg.Body = "Test mail";
        smtp.Timeout = 60000;
        smtp.Send(msg);
        result = true;
    }
    catch (Exception ex)
    {

    }

我的异常错误是

System.Net.Mail.SmtpException was caught
  HResult=-2146233088
  Message=Authentication failed.
  Source=System
  StackTrace:
       at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
       at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
       at System.Net.Mail.SmtpClient.GetConnection()
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at MailConfiguration.TestMail() in

【问题讨论】:

  • 可以telnet mail.myorganization.com 587看看结果如何
  • 你能建议怎么做吗? @Shetty
  • 在命令提示符下键入“telnet mail.myorganization.com 587”。使用正确的服务器名称
  • 我做了,它说 -- 'telnet' 不是被识别为内部或外部命令、可运行程序或批处理文件
  • 控制面板>程序>打开或关闭 Windows 功能。然后,检查“Telnet 客户端”并保存更改。您可能需要等待大约几分钟才能使更改生效。

标签: c# asp.net email ssl smtp


【解决方案1】:

我有一个非常相似的问题。尝试使用wireshark 来了解发生了什么问题。就我而言,我使用 System.Web.Mail 解决了这个问题。我知道它已被弃用,但您的情况与我的情况相似,我认为没有其他可能解决问题。

my solution

System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
    msg.Body = message.Body;

    string smtpServer = "mail.business.it";
    string userName = "username";
    string password = "password";
    int cdoBasic = 1;
    int cdoSendUsingPort = 2;
    if (userName.Length > 0)
    {
        msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer);
        msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
        msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsingPort);
        msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic);
        msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);
        msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
    }
    msg.To = message.Destination;
    msg.From = "me@domain.it";
    msg.Subject = message.Subject;
    msg.BodyFormat = MailFormat.Html;//System.Text.Encoding.UTF8;
    SmtpMail.SmtpServer = smtpServer;
    SmtpMail.Send(msg);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 2017-08-07
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    • 2016-09-05
    相关资源
    最近更新 更多