【问题标题】:Anybody knows how to send SSL emails with System.Net.Mail through GoDaddy email servers [closed]任何人都知道如何通过 GoDaddy 电子邮件服务器使用 System.Net.Mail 发送 SSL 电子邮件 [关闭]
【发布时间】: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.Mail answer 使用System.Net.Mail
  • 破折号,我收到“发送电子邮件失败”异常,内部异常是“无法发送电子邮件”,另一个内部异常显示“连接尝试失败,因为连接方在之后没有正确响应一段时间,或建立连接失败,因为连接的主机没有响应”
  • jrummell,不,我没有尝试过,因为该答案实际上对我不起作用。

标签: c# ssl smtpclient mailmessage


【解决方案1】:

.NET 内置邮件类不支持所需的 SSL 方法(隐式 SSL),与此无关:原因是 explained here

存在执行显式和隐式 SSL 并具有其他很酷功能的第三方 SMTP 客户端组件。例如,Rebex.Mail 或我们的SecureBlackbox

【讨论】:

    【解决方案2】:

    它不起作用的原因在于 SmtpClient 的体系结构。 SmtpClient 旨在使用纯文本而非 ssl 建立连接。

    不过,您可以使用 native.net 重新编写发件人。

    试试看 [Aegis Implicit Mail (AIM)] (http://netimplicitssl.sourceforge.net/) ,它是开源的,它的代码风格和架构与 System.Net.Mail 完全一样

    您可以在 [此处] (https://sourceforge.net/p/netimplicitssl/wiki/Home/) 找到有关 465(隐式“SSL”)和其他端口(显式“TLS”)的详细信息

    你可能是:

    try
    {
        MimeMailMessage 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
        MimeMailer smtpServer = new MimeMailer(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
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-29
      • 2011-06-08
      • 2021-05-06
      • 2013-04-02
      • 2013-02-04
      • 1970-01-01
      • 2018-10-17
      • 2014-01-11
      相关资源
      最近更新 更多