Priyank Patel
Priyank Patel

Reputation: 6996

Unable to send mail from ASP.NET web page

I have a Contact Us page in my website from which I am trying to send mail.Here is my code MailMessage feedBack = new MailMessage();

feedBack.To.Add("[email protected]");
feedBack.From = new MailAddress("[email protected]");
feedBack.Subject = "Mail from My Client's Website.";  
feedBack.Body = "Sender Name: " + Name.Text + "<br/><br/>Sender Last Name:"+LastName.Text+"<br/><br/>Sender Company:"+Company.Text+"<br/><br/>Sender Designation:"+Designation.Text+"<br/><br/>Sender Email:"+Email.Text+"<br/><br/>Sender Phone No:"+ PhoneNo.Text+"<br/><br/>Sender Enquiry:"+Enquiry.Text;
feedBack.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.MyClient.com"; //Or Your SMTP Server Address
//smtp.Port = 25;
//smtp.EnableSsl =false;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]","XXXX");
//Or your Smtp Email ID and Password
 smtp.Send(feedBack);

All the time I keep getting this error

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 64.37.118.141:25

I have verified with my client and all the details are correct(smtp server name,credentials).

I also tried setting port to 587 and 465 but it did not work.

Can someone help me out with this?

What can be the cause?

I am not able to find it. Any suggestions are welcome.

Upvotes: 4

Views: 1478

Answers (3)

EdSF
EdSF

Reputation: 12341

MEDIUM TRUST

If you are on a shared hosting service, chances are that ASP.Net is set to run in medium-trust (as it should). This restricts SMTP to port 25 only, you cannot use any other port.

Upvotes: 1

Alex Mendez
Alex Mendez

Reputation: 5150

I tested the ip above with port 25 through telnet and got the following response:

Command:

telnet 64.37.118.141 25

Response:

Could not open connection to the host, on port 25: Connect failed

Most likely port 25 is being blocked. You will need to find what port is used with your pop/smtp servers.

Upvotes: 2

Josh
Josh

Reputation: 10604

Have you checked that the server that the web application resides on is set up to be allowed to send mail through the SMTP server? Trust connections sometimes have to be setup to allow relaying off one server throught another.

Upvotes: 0

Related Questions