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