上周使用 SmtpCliet 发送邮件测试,在服务端配置 SSL 465 / 993 情况 ,客户端使用 465 SSL 端口发送邮件异常,测试代码如下:

 System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(RemoteServerCertificateValidationCallback);

                SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.Port = ;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
smtp.Host =txtSMTP.Text ;//指定SMTP服务器
.....

=>如上代码在 调用 smtp.send() 方法后 ,客户端假死,邮件服务器日志显示:

Performing SSL/TLS handshake for session 829. Verify certificate: False

=>将 smtp.EnableSsl 设为  false ,使用25端口,发送正常。 因此推断,加密通道验证有问题。 将邮件服务端 smtp:25 端口安全验证规则改为:  STARTTLS(Required) , smtp:465端口仍保持: SSL/TLS , 客户端代码如下 , 邮件发送成功。

System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(RemoteServerCertificateValidationCallback);

                SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
smtp.Host =txtSMTP.Text ;//指定SMTP服务器
.....
 private bool RemoteServerCertificateValidationCallback(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
Console.WriteLine(certificate); return true;
}

备注:

查阅MSDN , SmtpClient 版本只支持 Explicit SSL    客户端链路过程如: Connect on 25 -> StartTLS (starts to encrypt) -> authenticate -> send data

http://cn.bing.com/search?q=c%23+mail+ssl&FORM=QSRE1

https://stackoverflow.com/questions/1011245/how-can-i-send-emails-through-ssl-smtp-with-the-net-framework

https://blogs.msdn.microsoft.com/webdav_101/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465/

https://msdn.microsoft.com/zh-cn/library/system.net.mail.smtpclient.enablessl(v=vs.110).aspx

--隐示SSL 示例:

http://blog.csdn.net/qxyywy/article/details/73962948

SmtpClient SSL 发送邮件异常排查的更多相关文章

  1. C#发送邮件异常:根据验证过程,远程证书无效

    今天在做发送邮件功能时,开始用qq邮箱和163邮箱都可以正常发送,后再改用我公司的邮箱和smtp时竟然报错了. 异常提示-----"根据验证过程,远程证书无效",后来通过查询资料解 ...

  2. redis 异常排查

    异常排查 redis-server redis.windows.conf D:\redis-2.8.17>redis-server.exe redis.windows.conf[4692] 27 ...

  3. C#发送邮件异常:根据验证过程,远程证书无效,何解???

    /// <summary> /// 发送邮件 /// </summary> /// <param name="mailSubjct">邮件主题& ...

  4. System.net.mail 使用ssl发送邮件失败

    我采用了.net 的自带组件System.Net.Mail发送邮件,主要是在客户注册网站成功的时候发条欢迎邮件,最近邮件无法发送了,看了下腾讯smtp邮件配置,所有的邮件发送都换成ssl了,之前用的是 ...

  5. System.net.mail 腾讯ssl发送邮件超时

    我采用了.net 的自带组件 System.Web.Mail.MailMessage发送邮件,主要是在客户注册网站成功的时候发条欢迎邮件,最近邮件无法发送了,看了下腾讯smtp邮件配置,所有的邮件发送 ...

  6. C#发送邮件异常,返回信息乱码

    发邮件时出现了异常: 在 System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) 在 ...

  7. 【Redis连接超时】记录线上RedisConnectionFailureException异常排查过程

    项目架构: 部分组件如下: SpringCloudAlibaba(Nacos+Gateway+OpenFeign)+SpringBoot2.x+Redis 问题背景: 最近由于用户量增大,在高峰时期, ...

  8. javax.mail 发送邮件异常

    一.运行过程抛出异常 1.Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/ ...

  9. Java + 腾讯企业邮箱 + javamail + SSL 发送邮件

    说实话腾讯的企业邮箱真心不错! 腾讯企业邮箱官网:http://exmail.qq.com/login/ 新用户注册:http://exmail.qq.com/onlinesell/intro 点击开 ...

随机推荐

  1. 反转链表 Reverse Linked List

    2018-09-11 22:58:29 一.Reverse Linked List 问题描述: 问题求解: 解法一:Iteratively,不断执行插入操作. public ListNode reve ...

  2. Python 编程快速上手 第十七章 操作图像

    前言 在这一章节,讲了关于图像的三个方面的内容: 获得图像的相关信息:例如 RGBA 值,尺寸... 对图像进行编辑操作:例如 旋转,缩放... 在图像上绘制形状:例如 矩形,圆形... [Image ...

  3. springboot---->获取不到yml配置文件指定的值

    import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.Spr ...

  4. Django使用admin管理后台管理数据库表

    1.在admin.py文件中注册需要创建的表,例: from .models import * # Register your models here. admin.site.register(Use ...

  5. 『计算机视觉』Mask-RCNN_推断网络其三:RPN锚框处理和Proposal生成

    一.RPN锚框信息生成 上文的最后,我们生成了用于计算锚框信息的特征(源代码在inference模式中不进行锚框生成,而是外部生成好feed进网络,training模式下在向前传播时直接生成锚框,不过 ...

  6. Spring boot(三)在Spring boot中Redis的使用

    spring boot对常用的数据库支持外,对nosql 数据库也进行了封装自动化. redis介绍 Redis是目前业界使用最广泛的内存数据存储.相比memcached,Redis支持更丰富的数据结 ...

  7. 导出函数__declspec(dllexport)

    一般而言,动态链接库中定义有两种函数:导出函数(export function)和内部函数(internal function). 导出函数可以被其它模块调用,内部函数在定义它们的DLL程序内部使用. ...

  8. CF-503div2-A/B/C

    A. New Building for SIS time limit per test 1 second memory limit per test 256 megabytes input stand ...

  9. PAT 1031 Hello World for U

    1031 Hello World for U (20 分)   Given any string of N (≥) characters, you are asked to form the char ...

  10. 四、持久层框架(Hibernate)

    一.一级缓存与二级缓存 1.一级缓存:Hibernate默认是开启一级缓存的,一级缓存存放在session里,一个Session做一次查询操作,会把这个操作的结果放在一级缓存中,如果短时间内这个ses ...