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 );