xuzhimin

使用System.Net.Mail发送邮件时,发现使用25端口发送邮件正常,但使用465+SSL端口发送失败(163、qq、阿里云本身都不行,qq的587端口可用,但我们必须用vip.163发送),提示:无法从传输连接中读取数据: net_io_connectionclosed。

但使用阿里云的服务器25端口禁封,必须使用465发送。发现使用以下的代码可以正常发送,记录一下

// 邮件主题
System.Web.Mail.MailMessage mmsg = new System.Web.Mail.MailMessage();
//邮件主题
mmsg.Subject = "主题";
mmsg.BodyFormat = System.Web.Mail.MailFormat.Html;
//邮件正文
mmsg.Body = "内容";
//正文编码
mmsg.BodyEncoding = Encoding.UTF8;
//优先级
mmsg.Priority = System.Web.Mail.MailPriority.Normal;
//发件者邮箱地址
mmsg.From = "xxx@vip.163.com";
//收件人收箱地址
mmsg.To = "xxxx@qq.com";

mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//用户名
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "xxxx@vip.163.com");
//密码(授权码)
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "xxxx");
//端口
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);
//是否ssl
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
//Smtp服务器
System.Web.Mail.SmtpMail.SmtpServer = "smtp.vip.163.com";
try
{
SmtpMail.Send(mmsg);
Response.Write("发送成功");
}
catch (Exception ex)
{
Response.Write("发送失败,失败原因:" + ex.Message);
}

分类:

技术点:

相关文章:

  • 2021-05-01
  • 2021-11-28
  • 2022-01-21
  • 2021-11-26
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
猜你喜欢
  • 2022-03-07
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2021-12-04
  • 2021-12-26
  • 2022-02-11
相关资源
相似解决方案