简体   繁体   English

从Asp.Net/C#发送邮件时出错

[英]Error sending mail from Asp.Net/C#

I have built a feedback page.I am trying to send mail from the page.The client provided me with the SMTP Server name , Email ID and Password .But when I try to send mail from the page I am getting following error. 我已经建立了一个反馈页面。我正在尝试从页面发送邮件。客户端向我提供了SMTP Server名称, Email IDPassword 。但是当我尝试从页面发送邮件时,我收到了以下错误。

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

Here is my code 这是我的代码

MailMessage feedBack = new MailMessage();

//feedBack.To.Add("master@myclient.com");
feedBack.From = new MailAddress("master@myclient.com");
feedBack.Subject = "Mail from Explor Corporate 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+"Sender Phone No:"+ PhoneNo.Text+"Sender Enquiry:"+Enquiry.Text;
feedBack.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.myclient.com"; //Or Your SMTP Server Address
//smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("master@myclient.com", "*****");
//Or your Smtp Email ID and Password

smtp.Send(feedBack);

Can anyone help me out with this? 任何人都可以帮我解决这个问题吗?

Any suggestions are welcome. 欢迎任何建议。

This most likely indicates you don't have either the correct host name, or the correct port. 这很可能表示您没有正确的主机名或正确的端口。

If you are using SSL then the default SMTP port which is 25 will not work. 如果您使用的是SSL,则默认的SMTP端口25将无效。 I noticed that you did have a line setting the port what was commented out. 我注意到你确实有一条线设置了注释掉的端口。

Try setting the port to 587 and if that doesn't work, try port 465 which is sometimes used for secure SMTP. 尝试将端口设置为587,如果不起作用,请尝试端口465,有时用于安全SMTP。

If that doesn't work either confirm with your client the correct port and host name.. 如果这不起作用,请与您的客户确认正确的端口和主机名。

And another thing you may want to double check is whether the SMTP server you are using does indeed support/require SSL. 您可能想要仔细检查的另一件事是您使用的SMTP服务器是否确实支持/需要SSL。 If it does not support SSL that you will need to set the EnableSSL option to false and try connecting on the default port of 25 (or whatever port they are using). 如果它不支持SSL,则需要将EnableSSL选项设置为false并尝试连接默认端口25(或者它们正在使用的任何端口)。

Sounds like a possible timeout error or authentication problem. 听起来像是一个可能的超时错误或身份验证问题。 When accessing external resources from code you will need to handle possible errors: 从代码访问外部资源时,您需要处理可能的错误:

try
{
 smtp.Send(feedBack); 
}
catch(Exception e)
{
    // Handle the exception here
}

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

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