ASP.Net, CDO, and ‘The transport failed to connect to the server.’

A Web application (written in ASP.Net 1.1) that has run with no problems for months suddenly started giving a problem. The problem occurred when running the following code:

SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["SmtpServer"];

MailMessage msg = new MailMessage();
msg.BodyFormat = MailFormat.Text;
msg.From = ConfigurationSettings.AppSettings["returnEmailAddress"];
msg.To = formEmail.Value;
msg.Bcc = ConfigurationSettings.AppSettings["supportEmailAddress"];
msg.Subject = "My message subject";
msg.Body = FormatEmailBody();

SmtpMail.Send( msg );

You would think that would work fine, but it didn’t. At the SmtpMail.Send() command, the following error was thrown:

Server Error in ‘/’ Application.


The transport failed to connect to the server.

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.Runtime.InteropServices.COMException: The transport failed to connect to the server.
Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[COMException (0x80040213): The transport failed to connect to the server.]

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) +0
System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) +473
System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +58

[HttpException (0x80004005): Could not access 'CDO.Message' object.]
System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +111
System.Web.Mail.CdoSysHelper.Send(MailMessage message) +1861
System.Web.Mail.CdoSysHelper.Send(String from, String to, String subject, String messageText) +72
System.Web.Mail.SmtpMail.Send(String from, String to, String subject, String messageText) +167
MyApp.Web.SignUp.submitButton_Click(Object sender, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

I went through all the possible changes…

  • Recently adding the .Net Framework 2.0 to this machine: After re-registering the Web application to use ASP.Net 1.1, I still received the same error (as seen at the bottom of the error message). No problem here.
  • Bad permissions on IIS’s SMTP service: Authentication was anonymous. Relaying was allowed for the local computer. No other restrictions. Sending an email from SQL using CDO worked fine. No problem here
  • Restart services, reboot computer, bang mouse on desk, slam keys on keyboard: Didn’t help.

A quick Google search brought me to the System.Web.Mail Web site. Of all the ideas given in the site, one of them worked. From that Web site:

I have no idea why this suggestion works, but I found it on the web. I figured I would mention it, just in case Suggestion 1 did not work. Instead of specifying
SmtpMail.SmtpServer = “127.0.0.1”
try
SmtpMail.SmtpServer.Insert( 0, “127.0.0.1 or your mail server name here”)

Yes, it worked for me, too, by changing SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["SmtpServer"] to SmtpMail.SmtpServer.Insert( 0, ConfigurationSettings.AppSettings["SmtpServer"] ).

Don’t ask me why, either…

0 thoughts on “ASP.Net, CDO, and ‘The transport failed to connect to the server.’

  • I got same problem,with help of this code. Namespace for sending mails:using System.Web.Mail;
    MailMessage msg = new MailMessage();
    msg.From = “info@stargates.com”;
    msg.To = “sureshmdb@gmail.com”;
    msg.Subject =”Subject”;
    msg.Body =”Your Password is: ” s;

    SmtpMail.SmtpServer.Insert(0,”202.71.129.59″);
    SmtpMail.Send(msg);
    Response.Write (“”);
    Response.Write(“alert(‘Password Recovered Successfully. Check Your E-Mails ‘); window.open(‘index.aspx’,’_parent’);”);

  • please send me code for reading mail from smtp mailserver
    we have mail server so i want to make a application admin that read the specifide user mails with attachment
    please help me

  • You can’t read mail from an SMTP server; SMTP is a mail transmission protocol. You can read mail from a mailbox using POP or SMTP. Doing so is not complicated, but you need a library that supports POP and/or SMTP access (depending on the capabilities of your mail server).

    In the past I used libraries from http://www.nsoftware.com — they were very useful in accessing and manipulaing POP and SMTP mailboxes from code.

  • I am using CDO with ASP script to send email. The script was working fine in production till about days back. It suddenly stopped working giving the error of “The transport failed to connect to the server” No changes in any of the servers have been made.

    Interestingly, when I use my local PC and test the script without making any changes in the script whatsoever, things do seem to be working fine.

    In IIS I have even checked the relay option which is checked to allow all computers to relay.

    Where else could the problem be.

    Any assistance will be greatly appreciated.

    Regards,

    Vibhu Bansal.

  • Hi!

    I have the same problem.I use a com+ component(developed by me) to send mails with attachments.The mail component works fine for a few hours , but afterwards , I get the following error:
    “-2147220973:The transport failed to connect to the server”.What could cause this?

  • Is it possible your component is experiencing timeouts connecting to your server? Or, perhaps there’s something internally in the component (memory leak causing object failures, etc.)?

  • I’ll try to set the timeout to a bigger value…As for the memory leak…could you give me some examples?
    Sometimes I get this strange behaviour:I get the error described above , but I actually recieve the emails…

  • HI

    I got the error ” The Transport Failed to connect server”…
    But i got the solution from microsoft forms..
    I was using mcafe antivirus, tats wat the problem lied in my case…
    Antivirus blocks the outgoing mails using vs2005, iis 5.0,….

    My Solution to this Problem

    Go to virus console… and click on Access Protection.. and click on Prevent Mass mailing worms
    from sending mail..

    In Excluded Box… paste tis thing

    amgrsrvc.exe,tomcat.exe,outlook.exe,msimn.exe,agent.exe,WebDev.WebServer.exe,eudora.exe,nlnotes.exe,mozilla.exe,netscp.exe,opera.exe,winpm-32.exe,pine.exe,poco.exe,thebat.exe,thunderbird.exe,ntaskldr.exe,w3wp.exe,inetinfo.exe,nsmtp.exe,nrouter.exe,tomcat5.exe,tomcat5w.exe,ebs.exe,FireSvc.exe,modulewrapper.exe,MSKSrvr.exe,MSKDetct.exe

    ..

    Then it wil work…
    I did it .. it works for me..

  • //I have problem “transport connection failed” where i set in IIS relay restriction 127.0.01

    MailMessage mail = new MailMessage();

    mail.To = TextBox2.Text;

    mail.From = TextBox1.Text;

    mail.Subject = “txtSubject.Text”;

    mail.Body = TextBox3.Text;

    SmtpMail.SmtpServer = “127.0.0.1”;

    SmtpMail.Send(mail);

  • Hi,

    I am facing the same problem to send mails.

    Here is the code:
    SmtpMail.SmtpServer = “127.0.0.1”;
    MailMessage message = new MailMessage();

    message.From = txtEmailId.Text;
    message.To = “lakshmi_karnam@yahoo.co.in”;

    message.Subject = “Mail from Website”;
    message.Body = txtQuestion.Text;

    SmtpMail.Send(message);

    Error Details:
    System.Web.HttpException: The transport failed to connect to the server.
    —> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Runtime.InteropServices.COMException (0x80040213): The transport failed to connect to the server.

    — End of inner exception stack trace —
    at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
    at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
    at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
    — End of inner exception stack trace —
    at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
    at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message)
    at System.Web.Mail.SmtpMail.Send(MailMessage message)
    at Presentation_Contact.btnSend_Click(Object sender, EventArgs e)

  • Prashant Srivastava says:

    I am facing the same problem to send mails. ERROR : The transport failed to connect to the server

    protected void contactbtn_Click(object sender, EventArgs e)
    {

    string number = Session[“Number”].ToString().Trim();
    if ( number == codetxt.Text)
    {
    msg = new MailMessage();
    msg.From = mailtxt.Text.Trim(); ;
    msg.To = “prashant@paramtel.com”;
    msg.Subject = subtxt.Text.Trim();
    msg.Body = msgtxt.Text.Trim();
    msg.Fields.Add(“port”, “25”);
    SmtpMail.SmtpServer = “smtp.paramtel.com”;
    SmtpMail.Send(msg);

    verflbl.Text = “Email has been sent to our Call Wonder Team”;
    }
    else
    {
    verflbl.Text = “Verification Email not match. Please re-enter”;
    }
    }

  • Even i got the same error. Then i checked Default SMTP virtual server in IIS. It has been stopped. After i re-start, mails from mailroot (queue) started to send.

Leave a Reply to prakash Cancel Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.