C # The email attachment name is blank,

Source: Internet
Author: User
Tags mailmessage smtpclient

C # The email attachment name is blank,

Sample Code:

// 1. create MailMessage mailMsg = new MailMessage (); mailMsg. to. add (new MailAddress ("test@test.com"); // 2. set the mail title, body, and other information mailMsg. headersEncoding = Encoding. getEncoding ("gb2312"); mailMsg. subjectEncoding = Encoding. getEncoding ("gb2312"); mailMsg. bodyEncoding = Encoding. getEncoding ("gb2312"); // email Content Encoding mailMsg. subject = emailTitleStr; // mail title mailMsg. body = emailBodyStr; mailMsg. isBodyHtml = true; // whether the email content supports htmlmailMsg. priority = MailPriority. high; // attachment: In. net 4.0, when the attachment name contains a special name, the recipient will receive the attachment mailMsg whose name is null. attachments. add (new Attachment ("D: \ 6).txt"); // 3. create SMTP send SmtpClient smtp = new SmtpClient (emailSMTP, emailPort); smtp. credentials = new NetworkCredential (emailName. address, emailPwd); smtp. deliveryMethod = SmtpDeliveryMethod. network; smtp. send (mailMsg );

Problem description:When you use SmtpClient to add an attachment, if the attachment name is too long or contains special characters, the name of the attachment received by the email recipient is blank.

Cause:. Net 4.0 Bug.

Solution: Install the. net 4.5 or above class library.

. NET Framework 4.5:

Official Website: Https://www.microsoft.com/zh-cn/download/details.aspx? Id = 30653

Baidu: Http://rj.baidu.com/soft/detail/22370.html

 

 

====================================== Series of articles ==============================================

This article: 2.3 C # The Name Of The email attachment to be sent is blank

C # Article navigation

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.