我使用以下代码发送带有中文字符的附件(.csv)。但是,MS excel无法正确显示字符,它会显示类似“ å广–°ç”的字样。是因为我在发送邮件时没有设置某些属性吗?
感谢您的任何建议。
byte[] attachBytes = Encoding.UTF8.GetBytes(attachText);
ms.Write(attachBytes, 0, attachBytes.Length);
// Set the position to the beginning of the stream.
ms.Position = 0;
ContentType ct = new ContentType(MediaTypeNames.Text.Plain);
Attachment attactment = new Attachment(ms, attachFileName);
message.Attachments.Add(attactment);
Run Code Online (Sandbox Code Playgroud)
我认为您需要为邮件正文对象进行额外的编码设置,如下所示:
message.BodyEncoding = UTF8
Run Code Online (Sandbox Code Playgroud)