Some get error failure sending mail ( System.Net.Mail)

  • Thread starter Thread starter satnamsarai
  • Start date Start date
S

satnamsarai

Using System.Net.Mail: Sometimes I get error 'failure sending mail.
Unable to write data to the transport connection: An existing
connection was forcibly closed by the remote host.' Not sure how to
fix this error.

I am able to send messages sometimes both other times randomly
following error appear


EXCEPTION:
Exception of type 'System.Web.HttpUnhandledException' was thrown.
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext
context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.coursecert_presenter_main_aspx.ProcessRequest(HttpContext
context)
at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)
INNER EXCEPTION:
Failure sending mail.
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at coursecert.utility.SendEmail(Object from_email, Object
from_name, Object to_email, Object email_subject, Object
email_message)
at coursecert.utility.SendAMail(String email_subject, String
email_message, Int32 cert_tracking_id, String email_to)
at ASP.coursecert_presenter_main_aspx.SendMail(Int32 message_ind)
at
ASP.coursecert_presenter_main_aspx.btnSendtoPRODUCTION_click(Object
sender, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint)
INNER EXCEPTION:
Unable to write data to the transport connection: An existing
connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32
offset, Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32
size)
at System.Net.Mail.SmtpConnection.Flush()
at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String&
response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[]
command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,
MailAddressCollection recipients, String deliveryNotify,
SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
INNER EXCEPTION:
An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset,
Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32
offset, Int32 size)
 
An existing connection was forcibly closed by the remote host

Without seeing any code, the first thing that comes to mind (and has caught
me on a few projects) has been various anti-virus softwares blocking port
25 or the SMTP server you're using hasn't been provided with the correct
authentication information.

If you can, post up your code.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com
Using System.Net.Mail: Sometimes I get error 'failure sending mail.
Unable to write data to the transport connection: An existing
connection was forcibly closed by the remote host.' Not sure how to
fix this error.

I am able to send messages sometimes both other times randomly
following error appear

EXCEPTION:
Exception of type 'System.Web.HttpUnhandledException' was thrown.
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext
context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.coursecert_presenter_main_aspx.ProcessRequest(HttpContext
context)
at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApp
lication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)
INNER EXCEPTION:
Failure sending mail.
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at coursecert.utility.SendEmail(Object from_email, Object
from_name, Object to_email, Object email_subject, Object
email_message)
at coursecert.utility.SendAMail(String email_subject, String
email_message, Int32 cert_tracking_id, String email_to)
at ASP.coursecert_presenter_main_aspx.SendMail(Int32 message_ind)
at
ASP.coursecert_presenter_main_aspx.btnSendtoPRODUCTION_click(Object
sender, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.R
aisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint)
INNER EXCEPTION:
Unable to write data to the transport connection: An existing
connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32
offset, Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32
size)
at System.Net.Mail.SmtpConnection.Flush()
at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String&
response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[]
command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,
MailAddressCollection recipients, String deliveryNotify,
SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
INNER EXCEPTION:
An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset,
Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32
offset, Int32 size)
 
Without seeing any code, the first thing that comes to mind (and has caught
me on a few projects) has been various anti-virus softwares blocking port
25 or the SMTP server you're using hasn't been provided with the correct
authentication information.

If you can, post up your code.

-dl

--
David R. Longneckerhttp://blog.tiredstudent.com


Using System.Net.Mail: Sometimes I get error 'failure sending mail.
Unable to write data to the transport connection: An existing
connection was forcibly closed by the remote host.' Not sure how to
fix this error.
I am able to send messages sometimes both other times randomly
following error appear
EXCEPTION:
Exception of type 'System.Web.HttpUnhandledException' was thrown.
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext
context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.coursecert_presenter_main_aspx.ProcessRequest(HttpContext
context)
at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApp
lication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)
INNER EXCEPTION:
Failure sending mail.
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at coursecert.utility.SendEmail(Object from_email, Object
from_name, Object to_email, Object email_subject, Object
email_message)
at coursecert.utility.SendAMail(String email_subject, String
email_message, Int32 cert_tracking_id, String email_to)
at ASP.coursecert_presenter_main_aspx.SendMail(Int32 message_ind)
at
ASP.coursecert_presenter_main_aspx.btnSendtoPRODUCTION_click(Object
sender, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.R
aisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint)
INNER EXCEPTION:
Unable to write data to the transport connection: An existing
connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32
offset, Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32
size)
at System.Net.Mail.SmtpConnection.Flush()
at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String&
response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[]
command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,
MailAddressCollection recipients, String deliveryNotify,
SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
INNER EXCEPTION:
An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset,
Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32
offset, Int32 size)- Hide quoted text -

- Show quoted text -


Here is the code.. It work fine sometimes, but when this function is
called repealy, then it break down!..


Sub sendAmail()
Dim send_mail_ip As String =
System.Configuration.ConfigurationManager.AppSettings("send_mail_ip")
Dim mail As New MailMessage()

If Trim(txtToEmail.Text) <> String.Empty And
Trim(send_mail_ip) <> String.Empty Then
Dim smtp As New SmtpClient(Trim(send_mail_ip))
mail.From = New MailAddress(Trim(txtFromEmail.Text),
Trim(txtFromEmail.Text))
mail.To.Add(Trim(txtToEmail.Text))
mail.Subject = txtSubject.Text
mail.Body = txtMessage.Text

smtp.Send(mail)

lblAlert.Text = "<font color =""green"">Email Send</font>"
End If

End Sub
 
Back
Top