简体   繁体   English

无法从ASP.NET网页发送邮件

[英]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(); 我在我的网站上有一个联系我们页面,我正在尝试发送邮件。这是我的代码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 连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应64.37.118.141:25

I have verified with my client and all the details are correct( smtp server name,credentials ). 我已经与我的客户验证了所有细节都是正确的( smtp server name,credentials )。

I also tried setting port to 587 and 465 but it did not work. 我也尝试将端口设置为587和465,但它不起作用。

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: 我用端口25通过telnet测试了上面的ip,得到了以下响应:

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. 最有可能的端口25被阻止。 You will need to find what port is used with your pop/smtp servers. 您需要找到pop / smtp服务器使用的端口。

MEDIUM TRUST 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). 如果您使用共享主机服务, ASP.Net可能设置为以medium-trust (应该)运行。 This restricts SMTP to port 25 only , you cannot use any other port. 这限制SMTP端口25 ,不能使用任何其他端口。

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? 您是否检查过Web应用程序所在的服务器是否已设置为允许通过SMTP服务器发送邮件? Trust connections sometimes have to be setup to allow relaying off one server throught another. 有时必须设置信任连接以允许从一个服务器中继到另一个服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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