我的代码如下:
ContentType ct = new ContentType();
ct.MediaType = MediaTypeNames.Application.Octet;
ct.Name = "这是一个很长的中文文件名希望能用它在附件名中.Doc";
Attachment attach = new Attachment(stream, ct);
但是收到的附件不是中文文件名,我发现ct.Name变成了"=?utf-8?B?6L+Z5piv5LiA5Liq5b6I6ZW/55qE5Lit5paH5paH5Lu25ZCN5biM5pyb?=\r\n =?utf-8?B ?6IO955So5a6D5Zyo6ZmE5Lu25ZCN5Lit?="在 VS2010 调试器中。
请教,附件文件名中的中文字符怎么用?
最佳答案
你能试试吗:
Attachment att = new Attachment(@"c:\path to file\somename.txt",
System.Net.Mime.MediaTypeNames.Application.Octet);
//this itself should work.
att.Name = "история-болезни.doc"; // non-english filename
//if the above line doesn't make it work, try this.
att.Name = System.Web.HttpUtility.UrlEncode(att.Name, System.Text.Encoding.UTF8);
关于c# - C#SmtpClient编程如何设置中文附件文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4397332/