C # Send message attachment name is empty

Source: Internet
Author: User
Tags mailmessage smtpclient

Example code :

1. Create mail MailMessage mailMsg = new MailMessage () MailMsg.To.Add (New MailAddress ("[email protected]");//2. Set the message header, Message mailmsg.headersencoding = encoding.getencoding ("gb2312"); mailmsg.subjectencoding = Encoding.GetEncoding (" gb2312 "); mailmsg.bodyencoding = encoding.getencoding (" gb2312 "); Message content encoding Mailmsg.subject = EMAILTITLESTR; Message header Mailmsg.body = Emailbodystr;mailmsg.isbodyhtml = true; Whether the message content supports htmlmailmsg.priority = mailpriority.high;//attachment: in. NET 4.0, when the attachment name contains a special name, The receiving party will receive an attachment MAILMSG.ATTACHMENTS.ADD (new Attachment ("D:\ data") with an empty name);//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 add an attachment using SmtpClient, the attachment name that is too long or contains a special symbol causes the message receiver to receive an empty attachment name.

problem reason : a bug in. NET 4.0.

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

official website : https://www.microsoft.com/zh-cn/download/details.aspx?id=30653

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

================================== Series article ==========================================

This article: 2.3 C # Send message attachment name is empty

C # Article Navigation

C # Send message attachment name is empty

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.