c# - C#SmtpClient编程如何设置中文附件文件名?

标签 c# cjk smtpclient

我的代码如下:

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/

相关文章:

c# - 从控制台应用程序发送电子邮件时导致套接字异常的原因是什么?

c# - 移动断点 Visual Studio 2010

c# - 如何让 Microsoft Coded UI Test Builder 识别 ItemsControl?

c# - 异步线程 tcp 服务器

utf-8 - 简体中文和繁体中文的语言代码?

java - 当我使用 wkhtmltopdf 时,Unicode 字符被转换为损坏的符号

android - 如何在Android中对中文进行排序?

c++ - Smtp 客户端 - 从和不发送

c++ - 使用 SMTPS (TLS) 通过 gmail (smtp.gmail.com) 发送电子邮件的开源库

c# - ASP.NET MVC 3 动态表单生成