System.net.mail 使用ssl发送邮件失败
我采用了.net 的自带组件System.Net.Mail发送邮件,主要是在客户注册网站成功的时候发条欢迎邮件,最近邮件无法发送了,看了下腾讯smtp邮件配置,所有的邮件发送都换成ssl了,之前用的是25端口,现在换成了465或587,于是修改代码如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
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/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发送邮件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
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 hereSystem.Web.Mail.SmtpMail.SmtpServer = "smtp.qq.com";System.Web.Mail.SmtpMail.Send(mail);//return true;}catch (Exception ex){ex.ToString();} |
System.net.mail 使用ssl发送邮件失败的更多相关文章
- 利用System.Net.Mail 的SmtpClient发送邮件
原文:利用System.Net.Mail 的SmtpClient发送邮件 几个月前总结过关于Jmail发送邮件,当时用Jmail发送邮件发送速度有点慢(可能对Jmail了解不是很多).现在改为用微软提 ...
- System.Web.mail ----虚拟发件人发送邮件
转载别人的 使用SMTP发送邮件 说到邮件发送,先提一下SMTP. SMTP的全称是“Simple Mail Transfer Protocol”,即简单邮件传输协议.它是一组用于从源地址到目的 ...
- System.net.mail 腾讯ssl发送邮件超时
我采用了.net 的自带组件 System.Web.Mail.MailMessage发送邮件,主要是在客户注册网站成功的时候发条欢迎邮件,最近邮件无法发送了,看了下腾讯smtp邮件配置,所有的邮件发送 ...
- C#使用 System.Net.Mail发送邮件功能
.NET 里包含了很多很丰富的邮件发送与接受的API在 System.Net.Mail命名空间里,使得我们开发发送和接受邮件相关功能变得简单,下面是一个简单发送邮件的功能: private void ...
- 使用System.Net.Mail中的SMTP发送邮件(带附件)
System.Net.Mail 使用简单邮件传输协议SMTP异步发送邮件 想要实现SMTP发送邮件,你需要了解这些类 SmtpClient :使用配置文件设置来初始化 SmtpClient类的新实例. ...
- .net System.Web.Mail发送邮件 (设置发件人 只显示用户名)
http://blog.163.com/hao_2468/blog/static/130881568201141251642215/ .net System.Web.Mail发送邮件 2011-05- ...
- 在.net程序中使用System.Net.Mail来发送邮件
System.Net.Mail是微软自家提供的工具,在.net程序中可以使用该空间中的SmtpClient实例来实现邮件的发送. 使用System.Net.Mail空间与Web.config配置相配合 ...
- asp.net 发送邮件代码 System.Net.Mail
前台页面 SendEmail.aspx 代码 using System.Net.Mail;using System.Net; <h2> 发送电子邮件演示 </h2> <t ...
- 利用System.Net.Mail 发送邮件
我这里只是试了一下发mail的功能,感觉.net自带的发mail是比较全的,还是直接上我的code 参数文章:System.Net.Mail 发送邮件 SMTP协议 using System; usi ...
随机推荐
- 计算机存储单位KB,MB,GB,TB,PB,EB,ZB,YB后面是什么?
关于计算机存储单位KB,MB,GB,TB,PB,EB,ZB,YB后面是什么? 我们知道Kb是1000的1次方,所以 MB就是1000的2次方(106) GB就是1000的3次方(109) TB就是10 ...
- C语言强化——排序
1.完成堆排,对比堆排和qsort在排序1亿数的时间差异 #include<stdio.h> #include<time.h> #include<stdlib.h> ...
- [UE4]使用另一个相机Scene Capture Component 2D当小地图
挂一个相机(Scene Capture Component 2D)在人物角色的正上方,相机朝下,让UI上的某一块区域看到相机所显示的内容. 一.在人物角色正上方添加相机组件Scene Capture ...
- [UE4]删除动画:Remove from frame 5 to frame 18
从当前帧开始删除到结尾的动画帧
- Making a view in a listview invisible android
问题: I have a ListView that's using a custom adapter. I want to dynamically add/remove items from the ...
- PLMN概念和应用设置
PLMN概念和应用设置 1 PLMN概念 PLMN: PLMN(Public Land Mobile Network,公共陆地移动网络) 该网路必须与公众交换电话网(PSTN)互连,形成整个地区或 ...
- python类型强转&二级容器
Number 类型强转 int : ---->>> float, bool, complex, str Float : ---->> ...
- Linux打开TCP BBR拥塞控制算法
要求内核为4.9以上,如果不是,请升级内核. modprobe tcp_bbr echo "tcp_bbr" >> /etc/modules-load.d/module ...
- Html——拖放
设置元素为可拖放 首先,为了使元素可拖动,把 draggable 属性设置为 true : <img draggable="true" /> 拖动什么 - ondrag ...
- navicat创建存储过程的小问题
再简单的东西长时间不用了就会出错,特此即时的记录下来,以便以后参考! 转自:http://blog.csdn.net/winy_lm/article/details/49690633 以下为navic ...