C # available email sending code

Source: Internet
Author: User
Tags mailmessage smtpclient
Public Mailmessage initial ( String  Address) {mailmessage m_mail = New  Mailmessage ();  //  Sender M_mail.from = New Mailaddress ( "  * ***** @ 126.com  "  );  //  Recipient M_mail.to.add ( New  Mailaddress (Address ));  //  Topic M_mail.subject = "  The proxy has not been verified for a long time !!!  "  ;  //  Content M_mail.body = "  Please reopen it !!!  "  ;  // Subject and body encoding formats M_mail.subjectencoding = System. Text. encoding. utf8; m_mail.bodyencoding = System. Text. encoding. utf8;  //  The email body is HTML encoded. M_mail.isbodyhtml = True  ;  //  Priority M_mail.priority = System. net. Mail. mailpriority. High;  //  Add attachments. You can add multiple attachments. //  M_mail.attachments.add (new attachment ("C: \ 1.txt "));  //  Bcc cc recipient  M_mail.bcc.add (Address );  //  CC recipient  M_mail.cc.add (Address );  Return  M_mail;} A smtpclient Client = New  Smtpclient ();  // You can use split to intercept the user name in this location from the sender. Client. Credentials = New System. net. networkcredential ( "  ****  "  , Password); client. Port = 25  ; Client. Host = "  Smtp.126.com  "  ;  Try {Client. Send (initial (  "  * ***** @ QQ.com  "  ));  //  Clientscript. registerstartupscript (this. GetType (), "myscript", "<SCRIPT> alert ('sent successfully! ') </SCRIPT> "); Succmsg. Add ( "  Email sent!  " + "  * ***** @ QQ.com  " );  Return   True  ;}  Catch  (System. net. Mail. smtpexception ex) {succmsg. Add (  "  Failed to send email!  " + "  * ***** @ QQ.com  "  );  Return   False ;} 

 

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.