【发布时间】:2012-06-08 15:44:43
【问题描述】:
我在 SO 上对此进行了研究,但找不到真正完整的答案。 许多人,包括我自己,都能够通过 C# System.Net.Mail 使用端口 25 或 587 发送电子邮件,而不是使用 SSL。例如,请参见此处: https://stackoverflow.com/questions/1317809/sending-email-using-a-godaddy-account
其他人有使用 System.Web.Mail 的解决方案,但该解决方案已过时: How can I send emails through SSL SMTP with the .NET Framework?
但是,似乎没有人知道如何使用 SSL 和端口 465 发送电子邮件。有没有人有解决方案,或者至少知道为什么 SSL 在 C# 中不起作用?
这是我正在使用的代码:
try
{
MailMessage mail = new MailMessage("sender@yourdomain.com", receivingEmail, subject, body);
string host = "smtpout.secureserver.net";
int port = 465; // it's 465 if using SSL, otherwise 25 or 587
SmtpClient smtpServer = new SmtpClient(host, port);
smtpServer.Credentials = new NetworkCredential("sender@yourdomain.com", "yourpassword");
smtpServer.EnableSsl = true;
smtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpServer.Send(mail);
}
catch (Exception ex)
{
// do something with the exception
...
}
【问题讨论】:
-
您是否遇到了特定异常?如果是,请发布异常消息。否则,值得向 GoDaddy 提出支持请求。
-
试过修改
System.Web.Mailanswer 使用System.Net.Mail? -
破折号,我收到“发送电子邮件失败”异常,内部异常是“无法发送电子邮件”,另一个内部异常显示“连接尝试失败,因为连接方在之后没有正确响应一段时间,或建立连接失败,因为连接的主机没有响应”
-
jrummell,不,我没有尝试过,因为该答案实际上对我不起作用。
标签: c# ssl smtpclient mailmessage