Mail: JMail, System.Net.Mail, System.Web.Mail

这两天一直在解决邮件乱码的问题,尝试过很多办法,也都没有比较好的办法

测试时大概用了3个邮箱,公司的outlook, hotmail, gmail, 一般发生乱码都是在hotmail上,且发生的时候基本都是因为charset设置为big5, 然后正文中中英问混杂,且是中文简繁混杂,所以hotmail基本上就乱了

开始是用JMail发的,所以改成UTF-8或者big5都不行,不是这个乱,就是另外一个乱~

然后听说其他部门有用到的系统却没有乱码,后来查到原来用的是System.Web.Mail(这个在Framework1.0就已经有了,而我所接触的项目却貌似从来没搞过,最多搞过System.Net.Mail,还没真正实施)

说搬就搬,和JMail没什么大的区别,这里仅说几个要注意的地方
1. 邮件服务器可能需要验证发件人地址的正确性(即From)的正确性,开始测试的邮件服务器貌似没有check这个,线上的有用到,所以费了些周折来查,后来把From拼成如下样子就OK了

Code

2. 其他的一些设置

Sample Code

其中:sendusing的解释如下,也可参见msnd(http://msdn.microsoft.com/en-us/library/aa566484.aspx)

Name Value Description

cdoSendUsingPickup

1

Send the message by using the local SMTP service pickup directory.

cdoSendUsingPort

2

Send the message by using the network (SMTP over the network).

cdoSendUsingExchange

3

Send the message by using the Microsoft Exchange mail submission Uniform Resource Identifier (URI). This URI is found in the user's urn:schemas:httpmail:sendmsg mailbox folder property.

smtpauthenticate

Name Value Description

cdoAnonymous

0

Perform no authentication.

cdoBasic

1

Use the basic (clear text) authentication mechanism.

cdoNTLM

2

Use the NTLM authentication mechanism.

另外也有发现其他的一些mail组件

w3JMail, JMail.Net(这个就是会在邮件尾部加一个广告,比较讨厌~,目前还没找到办法解决掉~

System.Net.Mail也还比较好用

原文地址:https://www.cnblogs.com/forward/p/1346766.html