Duncan Bayne
Duncan Bayne

Reputation: 3949

Attachment filename not en/de-coded correctly when longer than 13 characters

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("[email protected]", "[email protected]")
    {
        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);

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 ("檢檢檢檢檢檢檢檢檢檢檢檢檢"):

https://i.sstatic.net/lm1Ey.png

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://i.sstatic.net/gvNMV.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?

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://i.sstatic.net/DYtCN.png

Upvotes: 3

Views: 2369

Answers (1)

Related Questions