C# &引用;“身份验证失败”;在Asp.Net中发送邮件时出错

C# &引用;“身份验证失败”;在Asp.Net中发送邮件时出错,c#,asp.net,email,ssl,smtp,C#,Asp.net,Email,Ssl,Smtp,即使搜索了许多站点,也没有找到答案 我正在使用VS2010(Framework 4.0)和SQL 2012,我们正在使用exchange server…相同的邮件配置在java应用程序中工作,但在c中不工作# 按钮点击代码为: try { SmtpClient smtp = new SmtpClient(); smtp.Host = "mail.myorganization.com" smtp.Port = "58

即使搜索了许多站点,也没有找到答案

我正在使用VS2010(Framework 4.0)和SQL 2012,我们正在使用exchange server…相同的邮件配置在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

我有一个非常类似的问题。试着用wireshark来了解出了什么问题。在我的例子中,我使用System.Web.Mail解决了这个问题。我知道这是不赞成的,但你的想法和我的相似,我认为没有其他的可能性来解决这个问题


你能做telnet mail.myorganization.com 587看看结果吗?你能建议怎么做吗@Shettyin命令提示符键入“telnet mail.myorganization.com 587”。如果服务器的名称正确,它会说--“telnet”不能被识别为内部或外部命令、可操作程序或批处理文件控制面板>程序>打开或关闭Windows功能。然后,选中“Telnet客户端”并保存更改。在更改生效之前,您可能需要等待几分钟。
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);