最近在项目中用DotNetOpenMail 这个组件发送Email,由于邮件主题是中文的,发送到邮箱后,邮件主题变成了乱码。
Subject:
=?
gb2312
?
Q
?
EMC
=
BC
=
AB
=
CB
=
D9
=
C1
=
AA
=
C3
=
CB
=
BA
=
CF
=
D7
=
F7
=
BB
=
EF
=
B0
=
E9
=
C6
?=
通过观察邮件头,我们可以看到,虽然主题的字符集是GB2312,但是却是使用的 是 QuotedPrintable(简写为Q)这种编码,正确的编码是Base64(简写为B)。
Subject:
=?
gb2312
?
B
?
RU1DvKvL2cGqw8u6z9f3u
++
w6cbav68gMTQ6Mjg
=?=
EmailMessage emailMessage
=
new
EmailMessage();
emailMessage.FromAddress
=
new
EmailAddress(“××××××”
);
emailMessage.AddToAddress(
new
EmailAddress(“××××××”
));
emailMessage.Subject
=
“EMC极速联盟合作伙伴期刊”;
//
以下两行代码用来解决邮件主题存在乱码的问题
emailMessage.HeaderCharSet
=
Encoding.GetEncoding(
"
GB2312
"
);
emailMessage.HeaderEncoding
=
EncodingType.Base64;