Click here to Skip to main content
15,917,579 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i have this code in my application to send an e-mail to such a receiver but i have the following error : The transport failed to connect to the server.

and here is my code :
C#
System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage();
                       message.From = "some address";
                       message.To = txtEmail.Text;
                       message.Subject = "Message Subject";
                       message.Body = "Message Body";

System.Web.Mail.SmtpMail.SmtpServer = "the company exchange host server address";
System.Web.Mail.SmtpMail.Send(message);


in the web.config :
HTML
<system.net>
  <mailsettings>
	<smtp deliverymethod="Network" from="sender address">
	  <network host="https://address" port="443" password="pass" username="user" defaultcredentials="true" />
        </smtp>
			
  </mailsettings>
</system.net>


if some one can help me in this .. coz i searched a lot through this and found nothing till now :(
Posted
Updated 30-Nov-11 20:32pm
v2

Error SmtpMail with asp.net: Transport failed to connect to the server

Cause:

This error message will be displayed when the application is attempting to send email and is failing to establish a connection with the SMTP server.
Another cause of this problem is Relay Permission with Smtp (virtual) server.

Most of the cases this happens when we need to use another server as smtp server except localhost server (local computer). Sometimes it can make problem in local computer also.

Then we must set the relay permission of the smtp server. The following steps are to set the permission:

1. Go to Start->Settings->Control Panel->Administrative Tools->IIS Maneger (Internet Information Services).

2. Go to Internet Information Services->Localhost(local computer)-> smtpserver.

3. Right Click smtp server and click properties.

4. In properties dialog ... General (tab) -> Check Name and IP of local computer

Click Advance if list is blank Add local computer IP and TCP port 25.

5. Click on Access Tab... Click Relay

a. Select Only the list below (option).
b. if list is blank Add local computer IP.
c. if you want to send mail from other computer of the network
add that computer IP also and in list you will see Granted (IP).
d. check true allow all computer ........

6. Ok then Apply (lol).

Try the program now with System.Web.Mail.SmtpMail.SmtpServer = "127.0.0.1" (smtp server ip)...

I hope this will help.
(If this really helps you,Please vote for my solution)
 
Share this answer
 
v2
hi

You have to create SmtpClient

C#
SmtpClient smtp = new SmtpClient(SMTPServer);
smtp.Credentials = new NetworkCredential(SMTPUserName, SMTPPassword);
smtp.Send(mailMessage);



Thanks
Joe
 
Share this answer
 
v3
hi,
use this namespace

using System.Net.Mail;


sample code:

SmtpClient smtpClient = new SmtpClient();
           MailMessage message = new MailMessage();
           ArrayList frmempName = null;
           ArrayList toempName = null;
           sb.AppendLine();
           sb.Append(frmempName[0].ToString());
           message.Body = sb.ToString();
           message.From = new MailAddress(frmempName[2].ToString());
           message.Subject = "Sample Mail";
           smtpClient.Send(message);


in web.config settings for mail option

XML
<system.net>
<mailSettings>
        <smtp>
        <network host="mail.net" port="587" userName="Admin" password="Adm!nn"/>
        </smtp>
    </mailSettings>
</system.net>


please check.
 
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