Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachments' names are "tcmime.xxxx.xxxx.xxxx.bin" #277

Closed
wayneguow opened this issue Jan 4, 2016 · 5 comments
Closed

Attachments' names are "tcmime.xxxx.xxxx.xxxx.bin" #277

wayneguow opened this issue Jan 4, 2016 · 5 comments
Labels
question A question about how to do something

Comments

@wayneguow
Copy link

If the attachment of a email has a file name which contains Chinese or non-ASCII characters and have a long length, no matter what the QQ mail is, sender or receiver, the mail's attachment in QQ mail's sent or in box shows as "tcmime.xxxx.xxxx.xxxx.bin", but other mail servers perform normal. You can see something about this in https://support.microsoft.com/en-us/kb/2402064

@wayneguow
Copy link
Author

I used "using BodyBuild" and "cast a MailMessage to a MimeMessage"

@jstedfast
Copy link
Owner

The mail client you are using to read the message does not support rfc2231 encoding. Most likely it expects the filename parameter to be encoded using the rfc2047 encoding (which was never legal to use for encoding parameter values... but sigh, some mail software just sucks).

There are 2 ways of controlling the encoding method used for parameter values.

The first way is to set the encoding method on each individual Parameter:

var attachment = bodyBuilder.Attachments.Add (.....);
foreach (var param in attachment.ContentDisposition.Parameters)
    param.EncodingMethod = ParameterEncodingMethod.Rfc2047;
foreach (var param in attachment.ContentType.Parameters)
    param.EncodingMethod = ParameterEncodingMethod.Rfc2047;

The second way is to set the default parameter encoding method on the FormatOptions used for writing out the message and/or MIME part(s):

var options = FormatOptions.Default.Clone ();
options.ParameterEncodingMethod = ParameterEncodingMethod.Rfc2047;

message.WriteTo (options, stream);

@jstedfast jstedfast added the question A question about how to do something label Jan 4, 2016
@wayneguow
Copy link
Author

I have seen the similar question--"Why do attachments with unicode filenames appear as "ATT0####.dat" in Outlook?" in http://www.mimekit.net/docs/html/FrequentlyAskedQuestions.htm#UntitledAttachments. I just don't know how to use the first way when I use BodyBuilder to add attachments to form a MineMessage, but now, I have tried the first way and get it.
for(int i = 0; i < builder.Attachments.Count(); i++)
{
Parameter param;
if (builder.Attachments.ElementAt<MimeEntity(i).ContentDisposition.Parameters.TryGetValue("filename", out param))
param.EncodingMethod = ParameterEncodingMethod.Rfc2047;
}
I succeed through these sentences, is it right?

@wayneguow
Copy link
Author

In a word, thank you for your great work!

@jstedfast
Copy link
Owner

Yes, I think your code will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about how to do something
Projects
None yet
Development

No branches or pull requests

2 participants