Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ALL,

I want to add one email option in my web application,if any person submit any query then it will send to any specific email id but having an error like "System.Runtime.InteropServices.COMException: The transport failed to connect to the server."

i am using this code


//System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
MailMessage msg = new MailMessage();
SmtpMail.SmtpServer = "localhost";
msg.To = "tnitin55@gmail.com";
msg.From = "tnitin55@gmail.com";
msg.Subject = "Customer Query";
msg.BodyFormat = MailFormat.Html;
msg.BodyFormat = MailFormat.Text;
msg.Body = "Name : ("+TextBox1.Text+")";
//msg.Body = "E-Mail : ("+TextBox2.Text+")";
//msg.Body = "Phone : ("+TextBox3.Text+")";
//msg.Body = "Check In : ("+TextBox4.Text+")";
//msg.Body = "Country : ("+DropDownList1.SelectedValue+")";
//msg.Body = "Query : ("+TextBox5.Text+") ";
SmtpMail.Send(msg);


any body can please help me.

any help will be appreciated .
Posted
Updated 24-May-12 2:13am
v2
Comments
[no name] 24-May-12 8:14am    
Format code snippets when posting

You need to ensure the setting for the smtp server are correct. Localhost is generally not used. Instead you should us the ip address, or dns name, of the server configured as your mail server.

A good place for these setting is in the web.confg file

XML
<system.net>
    <mailsettings>
      <smtp from="mail@maydomain.com">
        <network host="some_server" port="25" username="name" password="password" defaultcredentials="true" />
      </smtp>
    </mailsettings>
 </system.net>


You can also find tutorials here http://www.aspnettutorials.com/tutorials/email/[^]
 
Share this answer
 
see this article that demonstrates query form with sending mail
Send Mail / Contact Form using ASP.NET and C#[^]
 
Share this answer
 
See my answer here

error in asp.net code to send email[^]

Thanks
--RA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900