“由于意外的分组格式,握手失败".与SmtpClient [英] "The handshake failed due to an unexpected packet format" with SmtpClient

查看:97
本文介绍了“由于意外的分组格式,握手失败".与SmtpClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SmtpClient发送电子邮件,如下所示:

I use SmtpClient to send email as below code:

SmtpClient client = new SmtpClient("host", 587);
client.EnableSsl = true;

client.Credentials = new System.Net.NetworkCredential("user", "pass");

MailAddress from = new MailAddress("from_mail", String.Empty, System.Text.Encoding.UTF8);

MailAddress to = new MailAddress("to_mail");
MailMessage message = new MailMessage(from, to);
message.Body = "Say hello";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "Testing";
message.SubjectEncoding = System.Text.Encoding.UTF8;

client.Send(message);

如果我使用.Net Framework 4.5,它将引发以下错误:由于意外的数据包格式,握手失败.如果我使用.Net Framework 4.6.1,它将成功发送邮件.

If I use .Net Framework 4.5, it will raise the error:The handshake failed due to an unexpected packet format. If I use .Net Framework 4.6.1, it will send mail successfully.

请给我建议?

推荐答案

可能是TLS版本问题.

Could be a TLS version issue.

如果在初始化SMTP客户端之前将System.Net.ServicePointManager.SecurityProtocol设置为使用tls1.2,会发生什么情况?

What happens if you set System.Net.ServicePointManager.SecurityProtocol to use tls1.2 before initializing the SMTP client?

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

这篇关于“由于意外的分组格式,握手失败".与SmtpClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆