无法发送电子邮件

时间:2017-04-15 14:32:37

标签: c# asp.net smtp

我的网站托管在Godaddy服务器上。我正在尝试发送电子邮件,但我得到了#34;操作已经超时。"错误。我试过以下链接,但它不起作用。 GoDaddy email sending failed

Not Able To Send Email Via C#

到目前为止,我已尝试过代码。

在web.config中

<system.net>
<mailSettings>
  <smtp>
    <network host="smtpout.secureserver.net" userName="username" password="secret" />
  </smtp>
</mailSettings>
</system.net>

并在代码中

var SmtpClient = new SmtpClient();
SmtpClient.Send(frommail,tomail,subject,body);

我也试过下面的代码

MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(txtForgotEmail.Text));
msg.From = new MailAddress("email");
msg.Subject = "subject";
msg.Body = "msg body"
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("toemail", "secret");
client.Port = 25;
client.UseDefaultCredentials = false;
client.Send(msg);

P.S。我甚至无法从localhost发送电子邮件,也尝试了

client.EnableSsl = false;
client.UseDefaultCredentials = false;

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试将端口添加到设置

 <network host="smtpout.secureserver.net" userName="username" password="secret" port=25/>

对于要使用的端口,请参阅

https://sg.godaddy.com/help/what-do-i-do-if-i-have-trouble-connecting-to-my-email-account-319

使用SSL尝试所有25,80,3535和465