У меня возникли проблемы с отправкой электронной почты через 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 в качестве имени сервера, и оба отправленных письма находятся в нашей сети. Я подтвердил, что пароль и адрес электронной почты пользователя совпадают. Я просмотрел практически все ссылки через Google, и все говорят, что нужно использовать порт 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





Всем, у кого есть эта проблема, Проблема заключалась в том, что мы сбросили пароль для учетной записи, к которой я пытался получить доступ, и она оказалась заблокированной. Это устранило удаление и повторное создание учетной записи.