【求助】以前一直好好的,换了一个邮箱后SmtpClient邮件发不出去了,和TLS有关吗

sige100 2014-10-27 05:53:54
我以前做过一个利用163网站发送邮件的程序,一直跑得很好,最近邮件发不出去了,原因是因为该邮箱同样的信发得太多被定性为垃圾邮件了。我让客户注册一个企业邮箱,客户则丢给我另一个新的邮箱@outlook.com,发送参数:


接收 (POP3) 服务器

服务器地址:pop-mail.outlook.com

端口:995

加密连接:SSL

发送 (SMTP) 服务器

服务器地址:smtp-mail.outlook.com

端口:25(如果阻止了 25,则使用 587)

身份验证:是

加密连接:TLS



我已经按照设置打开了“通过 POP 连接设备和应用”(具体操作是按照http://windows.microsoft.com/zh-CN/windows/outlook/send-receive-from-app页面的“支持pop3和stmp的应用”一栏的描述一步步做下来的)
并且还开通了电子邮件转发(虽然我认为没什么用)
但是邮件总是发送失败
代码如下






public delegate bool SendEmailDelegate(string Title, string DisplayName, string Content, string Attachment, string FromAdress);

public static bool SendEmailFunct(string Title, string DisplayName, string Content, string Attachment,string FromAdress)
{

string EmailSMTP = ConfigurationManager.AppSettings["EmailSMTP"].ToString();
string HostAdd = ConfigurationManager.AppSettings["HostAdd"].ToString();
string HostPwd = ConfigurationManager.AppSettings["HostPwd"].ToString();
string PortNum = "25";
string EnableSSL = "true";

bool isSend = true;


MailMessage msg = new MailMessage();
msg.To.Add(FromAdress);
msg.From = new MailAddress(HostAdd, DisplayName, System.Text.Encoding.UTF8);
msg.Subject = Title;//标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = Content;//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = true;
//msg.Attachments = Attachment;
if (!string.IsNullOrEmpty(Attachment))
{
msg.Attachments.Add(new Attachment(Attachment));
}

SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(HostAdd, HostPwd);

client.Port = Convert.ToInt32(PortNum);
client.Host = EmailSMTP;
client.EnableSsl = Convert.ToBoolean(EnableSSL);//必须
object userState = msg;
try
{
client.Send(msg);
}
catch (Exception ex)
{
isSend = false;
}
return isSend;
}

public static void AsyncSendEmail(string Title, string DisplayName, string Content, string Attachment, string FromAdress)
{
SendEmailDelegate dele = new SendEmailDelegate(SendEmailFunct);
IAsyncResult ar = dele.BeginInvoke(Title, DisplayName, Content, Attachment, FromAdress, null, null);
}




上部和下部是托管代码不用管了,关键是中间SendEmailFunct方法,之前用163邮箱发从来没有问题,现在改用@outlook.com就发不出去,我看了半天唯一和163有区别的地方就是TLS了。之前163的代码SSL是关闭的,所以 EnableSSL是false,我查了一下TLS是SSL升级版所以我就把EnableSSL改成true了。不过EnableSSL不管是false还是true都是错的,如果EnableSSL是true,调试catch到的错是:无法从传输连接中读取数据: 您的主机中的软件中止了一个已建立的连接。。。(很长时间才会跳进catch),如果EnableSSL是false调试catch到的错是:System.Net.Mail.SmtpException: SMTP 服务器要求安全连接或客户端未通过身份验证。 服务器响应为: 5.7.0(几秒钟就跳进去了)。两个都度娘过,找不到解决方法。
各位来帮帮忙
...全文
833 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
小一马一哥 2016-01-18
  • 打赏
  • 举报
回复
我去,我现在也遇到相同的问题。tls的发送不了
changshenglugu 2015-11-05
  • 打赏
  • 举报
回复
请问楼主解决了没有?我用的是hotmail,返回5.7.3,也说客户端没通过身份认证

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧