简体   繁体   中英

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("some@some.com");
feedBack.From = new MailAddress("MyClient@some.com");
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("MyClient@some.com","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.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM