How to set Chinese character binding file name in C # SmtpClient programming?

my code is as follows:

ContentType ct = new ContentType();
ct.MediaType = MediaTypeNames.Application.Octet;
ct.Name = "这是一个很长的中文文件名希望能用它在附件名中.Doc";
Attachment attach = new Attachment(stream, ct);

but the received attribute does not match the correct Chinese file name, and I found ct.Name becames "=? utf-8? B? 6L + Z5piv5LiA5Liq5b6I6ZW / 55qE5Lit5paH5paH5Lu25ZCN5biM5pyb? = \ r \ n =? utf-8? Z56Z55Z65Z65Z65Z65Z6? 6o6? 5? 6o6? 5? 6? VS2010 debugger.

Plz tip, how can I use Chinese characters in the attachment file name?

+3
source share
3 answers

Can you try:

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);
+2
source

, . MIME- ASCII, (. RFC 2047).

, UTF-8 base-64 - , =?utf8?B?. .

: oops, , , . , , , , , , .

0

Finally, I found a workstation, according to RFC 2047, the delimiter can be CRLF or SPACE between "ecoded-word", and C # uses CRLF as the delimiter, but the NOTES / Gmail client cannot interpret it even after I replaced CRLF on SPACE, it works well in NOTE / Gmail.

Thanks Rup, your RCF2047 link will help me!

0
source

Source: https://habr.com/ru/post/1779375/


All Articles