附件文件名不是EN / DE-$ C $正确的CD时长超过13个字符文件名、时长、字符、附件

2023-09-04 01:01:15 作者:唱罢浮生曲

我使用下面的code发送的电子邮件附件。我使用C#,.NET 4.0,BPOS Exchange服务器来发送。

I am using the following code to send an email attachment. I'm using C#, .NET 4.0, BPOS Exchange server to send.

var message = new MailMessage("duncanbayne@example.com", "duncanbayne@example.com")
    {
        Subject = "Test Message"
    };
var ms = new MemoryStream(Encoding.UTF8.GetBytes("我希望這個作品。"));
var attachment = new Attachment(ms, "檢", "text/plain")
        {
            TransferEncoding = TransferEncoding.Base64
        };
message.Attachments.Add(attachment);

var server = new SmtpClient("smtpserver", 25);
server.Send(message);

这工作得很好。如果我逐步提高文件名的长度,东西继续工作,最多&安培;包括地步文件名是13个字符(检检检检检检检检检检检检检):

This works just fine. If I gradually increase the length of the filename, things continue to work, up to & including the point where the filename is 13 characters long ("檢檢檢檢檢檢檢檢檢檢檢檢檢"):

http://i.stack.imgur.com/lm1Ey.p​​ng

不过,如果我增加至14个字符(检检检检检检检检检检检检检检),东西就会出差错和文件名显示在Outlook中,就好像它已经错误地连接/解除的文件名长度 - codeD:

However, if I increase the filename length to 14 characters ("檢檢檢檢檢檢檢檢檢檢檢檢檢檢"), something goes awry and the filename appears in Outlook as though it's been wrongly en/de-coded:

https://m.xsw88.com/allimgs/daicuo/20230904/6252.png

在两种情况下,附件内容是完整的(我希望这个作品。)。只有该附件的名称被影响。

In either case, the attachment contents are intact ("我希望這個作品。"). Only the name of the attachment is affected.

显然,我打某种限制在这里的......可能有人请告诉我,我做错了什么?

Clearly I'm hitting some sort of limit here ... could someone please tell me what I'm doing wrong?

更新:的无论客户端是Gmail或Outlook 2010中但是,当客户端是Gmail和文件名是> 13个字符,会出现问题,该附件也出现在的身体消息:

Update: The problem occurs regardless of whether the client is Gmail or Outlook 2010. However, when the client is Gmail and the filename is > 13 characters, the attachment also appears in the body of the message:

https://m.xsw88.com/allimgs/daicuo/20230904/6253.png

推荐答案

原来,这是一个已知的问题,和放大器;微软已经发布了修复程序。请参阅:包含非ASCII字符,电子邮件附件名长度超过41 UTF-8 EN codeD字节是连接$ C $光盘被编译为.NET Framework 4 应用程序发送前两次

Turns out that this is a known issue, & Microsoft has issued a hotfix. See: An email message attachment name that contains non-ASCII characters and is longer than 41 UTF-8 encoded bytes is encoded two times before transmission in an application that is compiled for the .NET Framework 4.