开发者社区> 问答> 正文

465端口发送邮件失败

您好,我现在用C#编程发送邮件,用smtp.xxx.com.cn 25端口发送,可以发送成功。用465端口发送失败。主要代码如下:
方法一:
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
mailMessage.From = new MailAddress(_name);
mailMessage.To.Add(new MailAddress(destEmail));
mailMessage.Subject = "测试主题";
mailMessage.Body = "测试内容";
mailMessage.Priority = System.Net.Mail.MailPriority.High;
SmtpClient client = new SmtpClient();
client.Host = "smtp.xxx.com.cn";
client.Port = 465;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(_name, _pass);
ServicePointManager.ServerCertificateValidationCallback = delegate (Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; };
client.Send(mailMessage);
 
异常提示:无法从传输连接中读取数据: net_io_connectionclosed。
 
方法二:
System.Web.Mail.MailMessage mmsg = new System.Web.Mail.MailMessage();
            mmsg.Subject = title;// "zhuti1";//邮件主题
            mmsg.BodyFormat = MailFormat.Html;
            mmsg.Body = body;// "wqerwerwerwer";//邮件正文
            mmsg.BodyEncoding = Encoding.UTF8;//正文编码
            mmsg.Priority = System.Web.Mail.MailPriority.High;//优先级
            mmsg.From = from;//发件者邮箱地址
            mmsg.To = to;//收件人收箱地址
            mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username);
            mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
            mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);//端口
            mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
            System.Web.Mail.SmtpMail.SmtpServer = smtp;//ssl://smtp.xxx.com.cn 或 smtp.xxx.com.cn 都不行
            SmtpMail.Send(mmsg);
 
异常提示:与服务器的传输连接失败。
 
补充方法三:
qq邮箱1,添加其他邮箱 设置代理  smtp.xxx.com.cn  465  SSL  。
xxx@xxx.com.cn发送邮件到qq邮箱2,接收方能正常收到邮件。
qq邮箱1发送邮件到qq邮箱2,接收方无法收到邮件。
这能说明465端口正常还是不正常吗?

展开
收起
1738460227680622 2019-02-15 12:04:54 2532 0
2 条回答
写回答
取消 提交回答
  • 我也碰到这个问题,请问解决了吗?

    2020-05-28 09:29:18
    赞同 展开评论 打赏
  • 个人程序员一枚
    您可以先用其他软件尝试从465端口发送邮件测试, 看能否发送成功, 来验证是代码问题还是服务器问题
    2019-02-15 12:12:23
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载