. Net C # asynchronous sending requires that the receipt be embedded into image resources. custom email header failure notification. html/Text dual view supports notes emails.

Source: Internet
Author: User
Tags email string mailmessage smtpclient

Original post address: http://www.zu14.cn/2008/12/02/net_sendmail2/

In the previous. net mail article, we talked about the basic aspect. This article is a little more advanced.

Knowledge points:

  1. Embedded image resources in HTML-format emails
  2. Send a receipt to you after receiving the request
  3. If the email fails to be sent, send an Error Notification Email to you.
  4. Supports html/plain text dual-format mails, and the recipient can switch by itself
  5. Custom mail header
  6. Asynchronous transmission, supports canceling sending
  7. Email receipt, supporting Domino server of Lotus Notes
Smtpclient SMTP = new smtpclient (); SMTP. enablessl = false; SMTP. deliverymethod = smtpdeliverymethod. network; SMTP. host = "smtp.163.com"; SMTP. credentials = new networkcredential ("Triangle cat @ 163.com"," this is the password "); mailmessage Mm = new mailmessage (); mm. from = new mailaddress ("Triangle cat @ 163.com"," Triangle cat ", encoding. getencoding (936); mm. to. add ("Triangle cat @ gmail.com"); mm. subjectencoding = encoding. getencoding (1, 936); mm. subject = "Triangle Cat's test email, haha"; mm. bodyencoding = encoding. getencoding (936); // the content of a common text email. If the recipient's receiving client does not support HTML, This is a required string plaintextbody = "If your mail client does not support HTML format, or you can switch to the "plain text" view and 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.zu14.cn/\ "> really interesting Network </a>  "; // note the image resource alternateview htmlbody = alternateview embedded here. createalternateviewfromstring (htmlbodycontent, null, "text/html"); // process the embedded image watermark resource lrimage = New Custom Resource (@ "D: \ blogo.gif ", "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", "email address for receiving receipt @ 163.com"); // customize the mail header mm. headers. add ("X-Website", "http://www.zu14.cn/"); // Insert the receipt header mm for the Lotus Domino server. headers. add ("returnreceept", "1"); mm. priority = mailpriority. normal; // priority mm. replyto = new mailaddress ("Reply email Receiving address @ yahoo.com.cn", "Myself", encoding. getencoding (936); // if the message fails to be sent, the SMTP server will send an email to mm. deliverynotificationoptions = deliverynotificationoptions. onfailure; // process event SMTP when asynchronous sending is complete. sendcompleted + = new sendcompletedeventhandler (smtp_sendcompleted); // start sending SMTP asynchronously. sendasync (mm, null );
Void smtp_sendcompleted (Object sender, asynccompletedeventargs e) {If (E. cancelled) {MessageBox. show ("sent canceled");} else {If (E. error = NULL) {MessageBox. show ("sent successfully");} else {MessageBox. show ("failed to send:" + E. error. message );}}}

References: http://msdn.microsoft.com/en-us/vbasic/bb630227.aspx

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.