首页 技术 正文
技术 2022年11月16日
0 收藏 423 点赞 2,818 浏览 3351 个字

我采用了.net 的自带组件System.Net.Mail发送邮件,主要是在客户注册网站成功的时候发条欢迎邮件,最近邮件无法发送了,看了下腾讯smtp邮件配置,所有的邮件发送都换成ssl了,之前用的是25端口,现在换成了465或587,于是修改代码如下:

12345678910111213 MailMessage msgMail = new MailMessage("发件箱""收件箱""邮件标题""邮件内容");SmtpClient smtp = new SmtpClient("smtp.qq.com", 465);smtp.EnableSsl = true;smtp.DeliveryMethod = SmtpDeliveryMethod.Network;smtp.Credentials = new System.Net.NetworkCredential("发件箱""发件箱登录密码");try{smtp.Send(msgMail);}catch (Exception ex){Console.WriteLine("发送完毕......");}

这样还是不行,报操作已超时错误 在国外的技术网站上看到一句话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#利用CDO.Message发送邮件

如何引用CDO.Message? cod.message的引用位置: C:\Windows\System32\cdosys.dll

12345678910111213141516171819202122232425 CDO.Message objMail = new CDO.Message();try{objMail.To = "接收邮件账号";objMail.From = "发送邮件账号";objMail.Subject = "subject";//邮件主题string strHTML = @"";strHTML = strHTML + "这里可以填写html内容";objMail.HTMLBody = strHTML;//邮件内容objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = 465;//设置端口objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = "smtp.qq.com";objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = "发送邮件账号";objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress"].Value = "发送邮件账号";objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = "发送邮件账号";objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = "发送邮件账号";objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = "发送邮件账号登录密码";objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"].Value = "true";//这一句指示是否使用sslobjMail.Configuration.Fields.Update();objMail.Send();}catch (Exception ex) { throw ex; }finally { }System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail);objMail = null;

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

12345678910111213141516171819202122 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 authenticationmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername""发件人邮箱"); //set your username heremail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword""发件人邮箱密码"); //set your password heremail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);//set portmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl""true");//set is sslSystem.Web.Mail.SmtpMail.SmtpServer = "smtp.qq.com";System.Web.Mail.SmtpMail.Send(mail);//return true;}catch (Exception ex){ex.ToString();}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,997
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,356
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,139
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848