smtp.office365.com给出了net_io_connectionclosed

时间:2018-06-15 12:47:31

标签: c# email web smtp

我通过smtp发送电子邮件时遇到了一些问题,办公室里的任何人似乎都不知道该怎么做。我使用的是端口25,我尝试过587和465.

C#:

public void SendMail(string from, string to, string subject, string body, 
string attachments, string pwd)
    {
    string mailServerName = 
ConfigurationManager.AppSettings["smtpServer"].ToString();
    int mailPortName = int.Parse(ConfigurationManager.AppSettings["Port"]);

    try
    {
        using (MailMessage message = new MailMessage(from, to, subject, body))
        {
            message.IsBodyHtml = true;
            SmtpClient mailClient = new SmtpClient(mailServerName, mailPortName);
            mailClient.Host = mailServerName;
            mailClient.EnableSsl = true;
            //mailClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
            mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            mailClient.UseDefaultCredentials = false;
            mailClient.Credentials = new NetworkCredential(from, pwd);
            mailClient.Send(message);
        }
    }
    catch (SmtpException ex)
    {
        throw ex;
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

我使用smtp.office365.com作为服务器名称,并且通过的两封电子邮件都在我们的网络中。我已验证密码和用户电子邮件匹配正常。我通过谷歌几乎每个链接都经历过,每个人都说要使用端口587,它应该可以工作,但在这种情况下,这并不能解决我的问题。

这是错误:

Server Error in '/' Application.
Unable to read data from the transport connection: net_io_connectionclosed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.

Source Error: 


Line 1231:            throw ex;
Line 1232:        }
Line 1233:    }
Line 1234:   
Line 1235:}

Source File: c:\inetpub\wwwroot\ReportForm.aspx.cs    Line: 1233 

Stack Trace: 


[IOException: Unable to read data from the transport connection: net_io_connectionclosed.]
 System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) +1927189
 System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) +269
 System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) +45
 System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) +79
 System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) +168
 System.Net.Mail.SmtpClient.Send(MailMessage message) +1568

 [SmtpException: Failure sending mail.]
 ReportForm.SendMail(String from, String to, String subject, String body, 
String attachments, String pwd) in c:\inetpub\wwwroot\ReportForm.aspx.cs:1233
ReportForm.imgbtnSubmit_Click(Object sender, ImageClickEventArgs e) in 
c:\inetpub\wwwroot\ReportForm.aspx.cs:1194
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +98
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +161
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

Version Information: Microsoft .NET Framework Version:2.0.50727.8784; ASP.NET 
Version:2.0.50727.8762

1 个答案:

答案 0 :(得分:0)

对于有此问题的任何人, 问题是我们对我尝试访问的帐户执行了密码重置,并且该密码被锁定。删除并重新创建固定的帐户。