System.net.mail 腾讯ssl发送邮件超时
我采用了.net 的自带组件 System.Web.Mail.MailMessage发送邮件,主要是在客户注册网站成功的时候发条欢迎邮件,最近邮件无法发送了,看了下腾讯smtp邮件配置,所有的邮件发送都换成ssl了,之前用的是25端口,现在换成了465或587,于是修改代码如下:
MailMessage msgMail = new MailMessage("发件箱", "收件箱", "邮件标题", "邮件内容",2);
SmtpClient smtp = new SmtpClient("smtp.qq.com", 465,2);
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential("发件箱", "发件箱登录密码",2);
try
{
smtp.Send(msgMail,2);
}
catch (Exception ex)
{
Console.WriteLine("发送完毕......",2);
}
这样还是不行,报操作已超时错误 在国外的技术网站上看到一句话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发送邮件。
详见我下面的2篇文章:
C#利用System.web.mail发送邮件
System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage(,2);
try
{
mail.To = "收件人邮箱";
mail.From = "发件人邮箱";
mail.Subject = "subject";
mail.BodyFormat = System.Web.Mail.MailFormat.Html;
mail.Body = "<font color='red'>body</font>"; mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1",2); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "发件人邮箱",2); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "发件人邮箱密码",2); //set your password here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465,2);//set port
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true",2);//set is ssl
System.Web.Mail.SmtpMail.SmtpServer = "smtp.qq.com";
System.Web.Mail.SmtpMail.Send(mail,2);
//return true;
}
catch (Exception ex)
{
ex.ToString(,2);
}
C#利用CDO.Message发送邮件
如何引用CDO.Message? cod.message的引用位置: C:\Windows\System32\cdosys.dll
CDO.Message objMail = new CDO.Message(,2);
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";//这一句指示是否使用ssl
objMail.Configuration.Fields.Update(,2);
objMail.Send(,2);
}
catch (Exception ex) { throw ex; }
finally { }
System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail,2);
objMail = null;
System.net.mail 腾讯ssl发送邮件超时的更多相关文章
- 使用System.Net.Mail中的SMTP发送邮件(带附件)
System.Net.Mail 使用简单邮件传输协议SMTP异步发送邮件 想要实现SMTP发送邮件,你需要了解这些类 SmtpClient :使用配置文件设置来初始化 SmtpClient类的新实例. ...
- .net System.Net.Mail 之用SmtpClient发送邮件 Demo
private static bool sendMail() { try { //接收人邮箱 string SendTo = "XXXXX@163.com"; //抄送人邮箱 st ...
- .net System.Net.Mail 之用SmtpClient发送邮件Demo
private static bool sendMail() { try { //接收人邮箱 string SendTo = "XXXXX@163.com ...
- System.net.mail 使用ssl发送邮件失败
我采用了.net 的自带组件System.Net.Mail发送邮件,主要是在客户注册网站成功的时候发条欢迎邮件,最近邮件无法发送了,看了下腾讯smtp邮件配置,所有的邮件发送都换成ssl了,之前用的是 ...
- C#使用 System.Net.Mail发送邮件功能
.NET 里包含了很多很丰富的邮件发送与接受的API在 System.Net.Mail命名空间里,使得我们开发发送和接受邮件相关功能变得简单,下面是一个简单发送邮件的功能: private void ...
- .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 的SmtpClient发送邮件
原文:利用System.Net.Mail 的SmtpClient发送邮件 几个月前总结过关于Jmail发送邮件,当时用Jmail发送邮件发送速度有点慢(可能对Jmail了解不是很多).现在改为用微软提 ...
随机推荐
- Mysql 使用Group 和Case When统计数据
项目是基于:thinkcmf的,新的需求是对各栏目的文章数量进行统计 SQl很简单,先根据分类ID进行分组,然后再通过CASE WHEN 再统计不同文章状态数量 ) as count , =已审核 , ...
- (转)HLSL,函数列表
中文列表 函数名 说明 abs 计算输入值的绝对值. acos 返回输入值反余弦值. all 测试非0值. any 测试输入值中的任何非零值. asin 返回输入值的反正弦值. atan 返回输入值的 ...
- Authentication and Authorization in ASP.NET Web API
You've created a web API, but now you want to control access to it. In this series of articles, we ...
- [Functional Programming] Arrow Functor with contramap
What is Arrow Functor? Arrow is a Profunctor that lifts a function of type a -> b and allows for ...
- FireDAC中的SQLite(一)
Windows client software,FireDAC supports two SQLite library linking modes: Static linking: the x86 s ...
- SuperMap iDesktop之导入数据
SuperMap作为一个平台软件有自己的数据格式,现要将ESRI的SHP数据导入到SuperMap的udb数据库中,可以完成导入,但也不得不说几点问题. 下面是ArcGIS中批量导入SHP的操作界面. ...
- 【转】java 线程的几种状态
java thread的运行周期中, 有几种状态, 在 java.lang.Thread.State 中有详细定义和说明: NEW 状态是指线程刚创建, 尚未启动 RUNNABLE 状态是线程正在正常 ...
- Swift语言精要 - 属性
1. Stored Property eg: var number: Int = 0 2. Computed Property eg: var area : Double { get { return ...
- pager-taglib分页处理的使用
pager-taglib是java中一个用于分页的小的框架.下面简单介绍一下它的具体使用. 一.环境的搭建: 将pager-taglib-2.0.war包拷贝到Tomcat的webapps下.启动To ...
- AfterAddJS
protected override string AfterAddJS() { return CanDoo.FineUI.Utility.AfterSaveJS_ReloadData(EntityI ...