繁体   English   中英

使用SSL的SMTP电子邮件消息不能与ASP.NET中的GoDaddy电子邮件地址一起使用

[英]SMTP email message with SSL not working with GoDaddy email address in ASP.NET

当我尝试在我的新GoDaddy电子邮件地址上使用SSL发送STMP电子邮件时,它不起作用。 我收到一条错误消息,指出Unable to read data from the transport connection: net_io_connectionclosed.

以下是服务器的电子邮件设置:

在此输入图像描述

这是我的web.config中包含电子邮件服务器信息的片段:

<system.net>
  <mailSettings>
    <smtp from="no-reply@mysite.com" >
      <network host="smtpout.secureserver.net" port="465" userName="no-reply@mysite.com" password="password123" enableSsl="true" />
    </smtp>
  </mailSettings>
</system.net>

这是发送电子邮件的C#代码。

MailMessage message = new MailMessage();
message.To.Add(new MailAddress(to));
message.Subject = "Message from " + inputModel.Name;
message.Body = body;
message.IsBodyHtml = true;

using (var smtp = new SmtpClient())
{
    smtp.Send(message);
}

端口80,3535和25在没有SSL的情况下工作正常,但四者中没有一个使用 SSL。 我甚至尝试使用SSL端口587,经过相当长的一段时间它才刚刚超时。

如何使用SSL发送这些电子邮件?

这个较老的问题中 ,包括对问题的描述 - SmtpClient仅支持“显式SSL”,你需要做“隐式SSL”直接在端口465上谈论SSL。

比那里讨论的那些选项更好,更现代的方法是使用具有隐式SSL支持的维护良好的库。 MailKit将是一个很好的方法。

或者,请考虑使用第三方电子邮件中继服务,例如SendGrid,Mandrill,Mailgun等。 这样做将大大提高用户在收件箱中实际接收邮件的可能性,而不是垃圾邮件/垃圾邮件文件夹。

从你的截图我假设你的网站是在godaddy之外托管所以你可以使用“smtpout.secureserver.net”。

如果您的网站托管在godaddy上,那么您需要更改配置如下:

 <system.net>
      <mailSettings>
       <smtp from="no-reply@mysite.com">
        <network host="relay-hosting.secureserver.net"/>
       </smtp>
      </mailSettings>
    </system.net>

如果要使用Explicit ssl尝试将端口从465更改为587

对于隐式SSL,我们使用了netimplicitssl

这是从这个答案中取得的样本

var mailMessage = new MimeMailMessage();
mailMessage.Subject = "test mail";
mailMessage.Body = "hi dude!";
mailMessage.Sender = new MimeMailAddress("you@gmail.com", "your name");
mailMessage.IsBodyHtml = true;
mailMessage.To.Add(new MimeMailAddress("yourfriend@gmail.com", "your friendd's name")); 
mailMessage.Attachments.Add(new MimeAttachment("your file address"));
var emailer = new SmtpSocketClient();
emailer.Host = "your mail server address";
emailer.Port = 465;
emailer.EnableSsl = true;
emailer.User = "mail sever user name";
emailer.Password = "mail sever password" ;
emailer.AuthenticationMode = AuthenticationType.PlainText;
emailer.MailMessage = mailMessage;
emailer.OnMailSent += new SendCompletedEventHandler(OnMailSent);
//Send email
emailer.SendMessageAsync();

// A simple call back function:
private void OnMailSent(object sender, AsyncCompletedEventArgs asynccompletedeventargs)
{
    Console.Out.WriteLine(asynccompletedeventargs.UserState.ToString());
}

暂无
暂无

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

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