System.Net.Mail支持Explicit SSL但是不支持Implicit SSL,而国内的邮件服务器支持的SSL几乎都是Implicit SSL。所以,如果使用国内邮件服务器发送SSL邮件,不能使用System.Net.Mail,可以利用CDO.Message发邮件。

C#利用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
CDO.Message objMail = new CDO.Message();
try
{
objMail.To = "接收人邮件帐号";
objMail.CC = "抄送人邮件帐号";
objMail.From = "发送人邮件帐号";
objMail.Subject = "邮件主题";
objMail.HTMLBody = "邮件内容";
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = 465;//端口
objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = "smtp服务器地址";
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();
objMail.Send();
}
catch (Exception ex) { throw ex; }
finally { }
objMail = null;