. Net.

Source: Internet
Author: User
Tags email string mailmessage smtpclient

This article describes how to embed the email content into an image in. net. For more information, see

The format of the image called by the mail content in routine 1 is the server code for sending the mail is: SmtpClient, the object for sending the mail, and the Code omitted is as follows: system. net. mail. mailMessage mailMessage = new System. net. mail. mailMessage (); mailMessage. from = "sender's mailbox"; mailMessage. to. add ("recipient email list"); mailMessage. CC. add ("cc Mail List"); mailMessage. subject = subject; AlternateView htmlBody = AlternateView. createAlternateViewFromString (content, null, "text/html"); required resource lrImage = new temporary resource ("a.jpg", "image/gif"); lrImage. contentId = "Email001"; htmlBody. administrative resources. add (lrImage); mailMessage. alternateViews. add (htmlBody); SmtpClient. send (mailMessage); example 2 code: 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 Ren Zhijie test"); mm. to. add ("renzhijie1990@vip.qq.com"); mm. subject = "sending emails with images"; string plainTextBody = "If your email client does not support HTML format, or you switch to the" common text "view, you will see this content"; mm. alternateViews. add (AlternateView. createAlternateViewFromString (plainTextBody, null, "text/plain"); // the content of the HTML-format email string htmlBodyContent = "if you see <B> This </B>, you can view emails in <span style = \ "color: red \"> HTML </span> Format <br> "; htmlBodyContent + = "<a href = \" http://www.jb51.net/ // % 22% 3EVA Entertainment Network </a> "; // note the image resource AlternateView htmlBody = AlternateView embedded here. createAlternateViewFromString (htmlBodyContent, null, "text/html"); required resource lrImage = new Custom Resource (@ "d: \ 1.jpg"," image/gif "); lrImage. contentId = "weblogo"; // The ContentId corresponds to the cid in the htmlBodyContent content. If the settings are incorrect, the htmlBody is not displayed. administrative resources. add (lrImage); mm. alternateViews. add (htmlBody); // indicates the receipt. mm. headers. add ("Disposition-Notification-To", "renzhijie1111@163.com"); // customize the mail header mm. headers. add ("X-Website "," http://www.jb51.net/ "); // Insert the receipt header mm for the lotus domino server. headers. add ("returnreceept", "1"); mm. priority = MailPriority. normal; // priority mm. replyTo = new MailAddress ("renzhijie1111@163.com", "Myself"); // if the sending fails, the SMTP server will send the failed email to tell me mm. deliveryNotificationOptions = DeliveryNotificationOptions. onFailure; // process event smtp when asynchronous sending is complete. sendCompleted + = new SendCompletedEventHandler (smtp_SendCompleted); // start sending smtp asynchronously. sendAsync (mm, null );

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.