SmtpContent use UTF-8 encoding in file names

Aug 25, 2014 at 3:11 PM
Hello higty.
I have a problem: when I attach files whose names contain non-latin characters
then in the mail, I get random characters or "???" or spaces instead of text.

Sample: "Новый текстовый документ.txt" convert to ">2K9 B5:AB>2K9 4>:C<5=B.txt"

I'm using Windows 7, which encodes the file names in UTF-8.
As a mail server using Gmail, tried and others.
I tried using System.Net.Mail.SmtpClient - works well.

My code:
var content = new SmtpContent();
//content.LoadFileData(file); //don't work
content.Name = Path.GetFileName(file);
Aug 26, 2014 at 1:18 AM

It seems to be caused by mail client parser problem.
HigLabo encode filename by RFC2231 but many client could not parse it correctly.
Gmail and could not RFC2231.
Content-Disposition: attachment;
GMail, encode filename like below.
Content-Disposition: attachment;    filename="=?ISO-2022-JP?B?GyRCJy8nYCdTJ20nWxsoQiAbJEInZCdWJ1wnYydkJ2AnUydtJ1sbKEIgGyRCJ1UnYCdcJ2UnXidWJ18nZBsoQi50eHQ=?="
This encoding is not correct in RFC.But it is used as old style and many mail client parse it correctly.
I'll add a feature that you can select how to encode filename in next release.
Aug 26, 2014 at 3:59 AM

I rapidly modified this bug.
You can get latest version from

You can set MimeWriter default encoding behavior by below code.
MimeWriter.Default.FileNameEncoding = FileNameEncoding.BestEffort;
MimeWriter.Default.MimeHeaderParameterEncoding = MimeHeaderParameterEncoding.Rfc2047;
But default settings may solve your file name encoding problem.
So, you don't have to do anything.
Only you have to do is to replace dll.

Aug 26, 2014 at 9:02 AM
Thanks for the quick reply. This hotfix partially helped.
With short file names work well (if the file name less than 16 characters).
Else I see "=?utf-8?Q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9 =D1=82=D0=B5=D0=BA=D1=81=D1=82 =D2=AB=E1=BF="
Settings FileNameEncoding and MimeHeaderParameterEncoding do not affect the final result.
Aug 26, 2014 at 11:29 PM

Please try
MimeWriter.Default.HeaderRfc2047Encoding = Rfc2047Encoding.Base64;
It may be solve your problem.
Aug 27, 2014 at 12:12 AM

I found this is a bug and fixed.
It cause only Rfc2047Encoding.QuotedPrintable.
Please get latest version from here.

I hope this solve your problem.

Marked as answer by MrRobespierre on 8/26/2014 at 7:04 PM
Aug 27, 2014 at 2:05 AM
Thank you very much! Now it works perfectly!