您好,我现在用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端口正常还是不正常吗?