System.Net.Mail.SmtpException: Failure sending mail

 Hi All,

i am sorry if i posted this in wrong forum. but i am stuck have no idea why i keep getting this error . i have mail server with my hosting company. its called ( mysite is my domain name. i do have the real domain name even thou i am displaying here). when a customer places a order online, he/she gets an order confirmation email saying that the order has been placed along with their confirmation number. now thats where the error is coming and displays the customer an custom error page to go back and try again. if they do , it finally gives them the order confirmation number after mail server started working again. as a result, its frustrating the customers and me too LOL.

here is the error 

 System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host     at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)     at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)     --- End of inner exception stack trace ---     at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)     at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count)     at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count)     at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)     at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)     at System.Net.Mail.SmtpReplyReader.ReadLine()     at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)     at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)     at System.Net.Mail.SmtpClient.GetConnection()     at System.Net.Mail.SmtpClient.Send(MailMessage message)     --- End of inner exception stack trace ---     at System.Net.Mail.SmtpClient.Send(MailMessage message)     at checkout_purchase.sendConfirmationEmail(Order confirmedOrder) in c:\Websites\gn4f4ada\checkout\purchase.aspx.cs:line 214     at checkout_purchase.ibConfirm_Click(Object sender, ImageClickEventArgs e) in c:\Websites\gn4f4ada\checkout\purchase.aspx.cs:line 177

and line 177 in purchase.aspx.cs is as follows

 sendConfirmationEmail( Basket.Order );

and the code for sendConfirmationEmail is 


private void sendConfirmationEmail( Order confirmedOrder )
            SmtpClient MailRelay = new SmtpClient(
                ConfigurationManager.AppSettings[ "SmtpRelay" ] );
            MailRelay.DeliveryMethod = SmtpDeliveryMethod.Network;
            MailRelay.UseDefaultCredentials = true;

            MailMessage Email = new MailMessage( );
            Email.To.Add( confirmedOrder.Email );
            Email.From = new MailAddress( "" );
            Email.Subject = string.Format(
                " Confirmation - Order #{0}",
                confirmedOrder.Id );

            Email.Body = string.Format(
                getEmailBody( ),
                confirmedOrder.Id );

            Email.IsBodyHtml = false;

            MailRelay.Send( Email );
        //catch ( Exception ex )
            // swallow email exceptions and carry on for now

 can some one please help me out. Thanks a lot i really appreciate it.


3/4/2009 6:37:09 PM 91979 articles. 4 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 27

 I am sure the problem is with you email server. To pin point that just create a small routine to send a random email using your email server and see if it works or not.

Mark as an answer if it helps.
3/4/2009 7:06:01 PM

 Hello ,

Thanks for replying. i have contacted my hosting company and they told me to change this code . but i am not sure if that will help, is there anyway you can tell me if the apporach given by my hosting company is good one. sorry just trying to be careful, this website is my baby .

they told me that  MailRelay.DeliveryMethod = SmtpDeliveryMethod.Network;  is not needed and then also change the below line

MailRelay.UseDefaultCredentials = true;  to

Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}


MailRelay.Credentials = new System.Net.NetworkCredential("",



what i am asking is if this is a good apporach and if it is good one then can i use the from email address as the valid email adress in the above line.


thanks once again. i appreciate it.


3/4/2009 7:22:45 PM

Similar Artilces:

Sending Email through System.Net.Mail is generating errors "Failure Sending mail
hi Sending Email through System.Web.Mail is working fine but System.Net.Mail is generating errors "Failure Sending mail  i treid in all possible ways but did't  pls help in giving a solution thanks & Regards vittal Maybe you can show us some code and post the exact error mesg as well (by looking at the value in ex.tostring)?My HomePage -"It is more blessed to give than to receive." Acts 20: 35 (NIV, Bible)Progress - "Never discourage anyone...who continually makes progress, no matter how slow." Plato System.Web.Ma...

.net 2 beta 2 - System.Net.Mail
Hi guysI'm using the System.Net.Mail namespace in .net version 2, beta 2, to send out some HTML formatted e-mails.However, for some reason when the e-mail are sent out some of the full stops from the e-mail are removed.For example, part of the e-mail contains this code<img src="" alt="">But this is what the code is like when the e-mail source code is viewed<img src="" alt="">Is this a known bug in beta 2? If so, where can I view a list of known bugs an...

Why do Sending SMTP Authenticated E-mail succeed using SmtpMail.Send() function but fail using SmtpClient.send() function ? Bugs in System.Net.Mail.SmtpClient when send a Authenticated E-mail?
I click btnOK button, the email can send OK, but click btnFail button,  the following error is displayed! why ? you can test the section code. The SMTP, username, password are valid!  Many thanks! "Syntax error, command unrecognized. The server response was: authentication failed,decode user password error" I have tested some other SMTP, somes is OK. I think there are some bugs with System.Net.Mail.SmtpClient when send a Authenticated E-mail with some SMTP!   //------------------------------------------.ASPX Code----------------------------------------... not sending out mail
I recently upgraded from a 2.0 framework to 3.5 using c#.  When I upgraded, I needed to change the way I was using MailMessage.  But now for some reason it doesn't work.  Am I missing something?Below is my code:using; MailMessage msg = new MailMessage();msg.To.Add(toList);msg.CC.Add(ccList = null ? "" : ccList);msg.From = new MailAddress(fromList);msg.Subject = subject;msg.Body = body;msg.IsBodyHTML = true; SmtpClient smtp = new SmtpClient(smtpServer);smtp.Send(msg); I'm passing all the value from my web.config file inside AppSettings.What ...

About: how can i send a MIME(Text und Html Format) Mail by System.Net.Mail und .Net 2.0
Helle to all, I hope that someone can help me. I need to implement a programm to send newsletters. The newsletter Format can be Html, Text and MIME(Html and Text). when using CDONTS library man can set MailFormat = MIME. But i use System.Net.Mail and there are only text or html Format. Can someone tell me how can i use System.Net.Mail to send a MIME Mail? Thanks Best Regards Pinsha perhaps this link can help: this world there are 10 types of people, those that know binary and those who don't....

What additional advantage we get through over the old system.web.mail?
What additional advantage we get through over the old system.web.mail?Is it needed to configure the smtp server? Plz tell me the steps to develop the email sending facility in our applicationSwati Jain Take a look at Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue....

get mail using System.Net.Mail
How can i get Email usign System.Net.Mail ?? Hello poloxy  ,the System.Net.Mail used only for sending emails and not to receive them.Read the full documentation at  MSDN Library  Hosam Kamel Remember to click on Mark as answer on the post that helped you SO how can I receive mail ? Try one of these pop3 libraries  Hosam Kamel Remember to click on Mark as answer on the post that helped you HI,   if you want to send email by using System....

Value of type 'System.Net.Mail.MailMessage' cannot be converted to 'System.Net.Mail.AlternateView'
Trying to create an alternateview to send a txt email with the html formatted email.  I've used string builder to create the whole email, but I get this error.  Any ideas why?  i've bolded the line that throws the error... Dim EmailBodyTxt As New StringBuilder EmailBodyTxt.Append("<html><style type='text/css'>.table{border:solid; border-color:#006666; width:600;} ")EmailBodyTxt.Append("<body><table class='table'><tr><td colspan='2'><h1>Test<br />RESPONSE SYSTEM</h1></td>...

Error handling sending mail (
 Hi I did an aplication for send membership comunications and i want make a simple upgrade. I have a while for sent the messages to every recipients but i want in each recipient get if the mail has sent or failed, this is for sum that on a cell for the message but i dont know how get if the message go or failed?Im using VB. Somebody can help me on that?  You can't know for sure if the message was delivered or not. The only option would be to read any returned messages from the mail server. Website Design Darlington -

Problem in sending mail using
I am using C# and ASP.Net2.0 for sending mail. But my problem is it is not being sent. I am not being able to understand it. I am using my gmail account for it. I am using System.Net and System .Net.Mail for sending the same. But i am getting the error ''Failure Sending Mail. Cannot connect to the server" . I have internet connection. Plz help me. It's urgent. I am attaching my code.  MailMessage mailMsg = new MailMessage();MailAddress ma = new MailAddress(; mailMsg.From = ma; mailMsg.To.Add(s);mailMsg.Subject = "Your...

Sending Generic e-mail with
OK. This community is full of very smart and wonderful folks who have helped me out a lot. Here is another head scratcher for me. First off, here is my attached code in question. using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Collections.Generic;using System.Text;using System.Net.Mail;namespace dialogcoachdotcom{    public partial class contactus : System.We...

System.Net.Mail is giving error CS0029: Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'
I'm getting an error while trying to use the wizard to create a form and than pass it the vaibles to Mail. Any help would be much appreciated. SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try {   message.From = txtEmail.Text; message.To.Add(""); message.Subject = "Feedback"; message.CC.Add(""); message.CC.Add(""); message.IsBodyHtml = false; message.Body = txtMessage.Text; smtpClient.Send(message); lblStatus.Text = "Email successfully sent."; } catch (Exception ex) { lbl...

System.web.mail to
I converted a web app from VS 2003 to VS 2005. i now get error message when i build it  stating system.web.mail  is obsolute,  use i redefine to but now i get other error message such as smtpMail does not exist in the current context. cannot implicitly convert type string to System.Net.Mail.MailAddress   so System.Web.Mail want work in web app convert to VS 2005 running on framework 2.0?           because if i change to System.Net.Mail  i am ...

Web resources about - System.Net.Mail.SmtpException: Failure sending mail -

Resources last updated: 1/5/2016 7:01:56 PM