Closed ROMYIM closed 1 month ago
附件名称测试-1.zip the entire e-mail is in the zip-file
Took a quick look at the code and it looks like you are right - the charset string value is not getting used
Can you confirm whether or not your FormatOptions.International
value was true
when you sent the message?
I set theFormatOptions
later, but the char-set is still utf8.
SendMail Code
mailMessage.Body = bodyBuilder.ToMessageBody();
var formatOptions = new FormatOptions()
{
International = true
};
await smtpClient.SendAsync(formatOptions, mailMessage, cancellationToken);
Not only attchment's charset but also
MimeMessage.From
s' andMimeMessage.To
s' is not in effect.
Both FormatOptions.International
and FormatOptions.AllowMixedHeaderCharsets
are set to true
, the char-set is still utf8
Can you confirm whether or not your
FormatOptions.International
value wastrue
when you sent the message?
the FormarOptions
is Default
.
The above fixes that I committed yesterday should fix the issue.
For what it's worth, FormatOptions.International is supposed to enable Unicode Email (which it technically still isn't doing after my fix, but it also sounds like that's not what you want). In other words, MimeKit shouldn't be encoding email headers at all when FormatOptions.International is set to true.
You can test my fixes by using the latest NuGet package from here: https://www.myget.org/feed/mimekit/package/nuget/MimeKit
Thanks, but it doesn't work!
There is interesting thing that the value is 'gb180130....'
but ParseOptions.CharsetEncoding
is UTF8Encoding
I am not sure whether the MimeMessage
was encoded by ParseOptions.CharsetEncoding
when SmtpClient
sent the message.
ParserOptions.CharsetEncoding is only used for parsing and is the fallback charset in case it encounters unencoded 8bit headers. It's not anything you should be concerned about for this.
1 thing I should add, though, is that if you want it to use the =?gb18030?b?...?= style of encoding is that you can do this:
attachment.ContentDisposition.Parameters.Add(new Parameter("GB18030", "filename", mailAttachment.FileName) { EncodingMethod = ParameterEncodingMethod.Rfc2047 });
attachment.ContentType.Parameters.Add(new Parameter("GB18030", "name", mailAttachment.FileName) { EncodingMethod = ParameterEncodingMethod.Rfc2047 });
In general, the default encoding method should be used, but some mail clients only understand the rfc2047 encoding method. I'm not sure if that is important for your usage or not.
Just as you said, some mail clients only understand the rfc2047 encoding method such as outlook 2019 or enterprise wechat client.
Otherwise, there is a bug that the new windows mail client saves the mail and the source code always displays utf8 charset.
In fact, the charset setting with gb18030
is effective. I'm sorry.
Thank your answers and support!
Describe the bug I use
BodyBuilder
to set attachment's encoding GB18030. But the encoding is still utf8.Platform (please complete the following information):
My Code
Mail Content