. Net.

Source: Internet
Author: User
Tags mailmessage smtpclient

Routine 1


The format of the email content call image is:

The server code for sending an email is:

SmtpClient: email sending object // Code omitted

Copy codeThe Code 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 required resource ("a.jpg", "image/gif ");
LrImage. ContentId = "Email001 ";
HtmlBody. Administrative resources. Add (lrImage );
MailMessage. AlternateViews. Add (htmlBody );
SmtpClient. Send (mailMessage );

Example 2

Copy codeThe Code is 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 Ren Zhijie test ");
Mm. To. Add ("renzhijie1990@vip.qq.com ");

Mm. Subject = "sending an email with images ";

String plainTextBody = "If your mail 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 "));

//// HTML-format email content
String htmlBodyContent = "if you see <B> This </B>, it means that you are using <span style = \" color: red \ "> View emails in HTML </span> Format <br> ";
HtmlBodyContent + = "<a href = \" http://www.jb51.net//410223793eva </a> "; // pay attention to the image resources embedded here
AlternateView htmlBody = AlternateView. CreateAlternateViewFromString (htmlBodyContent, null, "text/html ");


Required resource lrImage = new required resource (@ "d: \ 1.jpg"," image/gif ");
LrImage. ContentId = "weblogo"; // The ContentId corresponds to the cid in htmlBodyContent. If the setting is incorrect, the image is not displayed.
HtmlBody. Administrative resources. Add (lrImage );

Mm. AlternateViews. Add (htmlBody );

//// Indicates the receipt request
Mm. Headers. Add ("Disposition-Notification-To", "renzhijie1111@163.com ");

//// Customize the mail header
Mm. Headers. Add ("X-Website", "http://www.jb51.net /");

//// Insert a receipt header for the LOTUS DOMINO SERVER
Mm. Headers. Add ("returnreceept", "1 ");

Mm. Priority = MailPriority. Normal; // Priority
Mm. ReplyTo = new MailAddress ("renzhijie1111@163.com", "Myself ");

//// If the message fails to be sent, the SMTP server will send a failed email to me.
Mm. DeliveryNotificationOptions = DeliveryNotificationOptions. OnFailure;

/// Processing Event upon completion of asynchronous sending
Smtp. SendCompleted + = new SendCompletedEventHandler (smtp_SendCompleted );

/// Start asynchronous transmission

Smtp. 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.