最近使用腾讯企业邮箱发送邮件的一些问题

腾讯企业邮箱使用SSL时,原来的邮件发送程序一直提示参数错误

SmtpClient _smtpClient = new SmtpClient();
                _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
                _smtpClient.Host = host; ;//指定SMTP服务器
                _smtpClient.Credentials = new System.Net.NetworkCredential(email, pwd);//用户名和密码
                _smtpClient.Port = 465;//使用的端口    
                _smtpClient.EnableSsl = true;//经过ssl加密   

端口与使用SSL都是配制正确的,但是一直发送不出去

找到以下资料 地址:http://www.ie81.com/Technology/225.html

这样还是不行,报操作已超时错误 在国外的技术网站上看到一句话System.Net.Mail支持Explicit SSL但是不支持Implicit SSL,然后查了下关于这两个模式的资料,我按照我理解的说一下:

Explicit SSL 发起于未加密的25,然后进行一个starttl握手,最终切换到加密的连接。

Implicit SSL 直接从指定的端口发起starttl握手。

既然指定了端口,那么应该就是使用了Implicit SSL,不知道微软什么时候能更新下System.net.mail,System.net.mail能在邮件中嵌入图片的。问题到了这里,那是不是就没有办法利用腾讯邮箱发邮件了呢?答案肯定是否定的,foxmail不就可以配置发送邮件吗?我们可以利用CDO.Message和System.web.mail发送邮件。

C#利用System.web.mail发送邮件

System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
try
{
mail.To = "收件人邮箱";
mail.From = "发件人邮箱";
mail.Subject = "subject";
mail.BodyFormat = System.Web.Mail.MailFormat.Html;
mail.Body = "body";
    
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "发件人邮箱"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "发件人邮箱密码"); //set your password here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);//set port
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");//set is ssl
System.Web.Mail.SmtpMail.SmtpServer = "smtp.exmail.qq.com";
System.Web.Mail.SmtpMail.Send(mail);
//return true;
}
catch (Exception ex)
{
ex.ToString();
}

通过以上的方法,就可以正常调用腾讯企业邮箱进行邮件发送了

原文地址:https://www.cnblogs.com/gxivwshjj/p/7562311.html