Specific instances of embedded pictures in. NET for sending message content

Source: Internet
Author: User
Tags mail mailmessage smtpclient

  This article mainly introduces the specific examples of embedded pictures in. NET, which can be referenced by friends in the following

Routine one   message content call picture format is: <img src= "cid:email001" >   Send the message of the service-side code:   SmtpClient Send the object/code of the message omitted the   code as follows: S Ystem. Net.Mail.MailMessage MailMessage = new System.Net.Mail.MailMessage (); Mailmessage.from= "sender's mailbox"; MAILMESSAGE.TO.ADD ("Recipient mailing List"); MAILMESSAGE.CC.ADD ("CC's Mailing List"); Mailmessage.subject = Subject; AlternateView htmlBody = alternateview.createalternateviewfromstring (Content,null, "text/html"); Linkedresource lrimage = new Linkedresource ("A.jpg", "image/gif"); Lrimage.contentid = "Email001"; HTMLBODY.LINKEDRESOURCES.ADD (Lrimage); MAILMESSAGE.ALTERNATEVIEWS.ADD (HtmlBody); Smtpclient.send (MailMessage);     Routine two   code as follows: SmtpClient SMTP = new SmtpClient (); Smtp. Deliverymethod = Smtpdeliverymethod.network; Smtp. Host = "smtp.163.com"; Smtp. Credentials = new NetworkCredential ("renzhijie1111", "* *");   MailMessage mm = new MailMessage (); Mm. from = new MailAddress ("renzhijie1111@163.com", "Invincible Zhinzhije test"); Mm. To.add ("renzhijie1990@vip.qq.com");   MM. Subject = "Sendwith picture Mail ";   String plaintextbody = "If you mail client does not support HTML format, or you switch to normal text view, you will see this content"; Mm. Alternateviews.add (alternateview.createalternateviewfromstring (plaintextbody, NULL, "Text/plain"));  ////html format Mail content string htmlbodycontent = "If you see <b> this </b&gt, you are in <span style=" color:red "> html</span> format View mail <br><br> "; Htmlbodycontent + = "<a href=" Http://www.jb51.net//%22%3EVA Entertainment network </a> <img src= "Cid:weblogo" >;  /Note the image resources embedded here AlternateView HtmlBody = alternateview.createalternateviewfromstring (htmlbodycontent, NULL, " Text/html ");     Linkedresource lrimage = new Linkedresource (@ "d:1.jpg", "image/gif"); Lrimage.contentid = "Weblogo"; The ContentID here corresponds to the CID in the Htmlbodycontent content: If the settings are not correct, the picture HtmlBody.LinkedResources.Add (Lrimage) is not displayed;   MM. Alternateviews.add (HtmlBody);  ////Request receipt of the logo mm. Headers.add ("Disposition-notification-to", "renzhijie1111@163.com");  ////Custom message header mm. Headers.add ("X-website", "http://www.jb51.net/"); &nbSp For LOTUS DOMINO SERVER, insert receipt head mm. Headers.add ("Returnreceipt", "1");   MM. Priority = Mailpriority.normal; Priority mm. ReplyTo = new MailAddress ("renzhijie1111@163.com", "Myself");  ////If the send failed, the SMTP server will send a failed message to tell me mm. Deliverynotificationoptions = deliverynotificationoptions.onfailure;  ////processing Event SMTP when the asynchronous send completes. sendcompleted + = new Sendcompletedeventhandler (smtp_sendcompleted);  ////begins asynchronous send   SMTP. SendAsync (mm, NULL);  

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.