Use System. net. Mail. mailmessage to send an email

Source: Internet
Author: User

The company sent an email a few days ago. The system. Web. Mail. mailmessage class was used, but it always felt unstable. I want to find a convenient and stable method to send emails. Later I found that a new class, system. net. Mail. mailmessage, was introduced from. NET 2.0. Let's take a look!

The system. net. Mail. mailmessage class is used to specify a mail, and the system. net. Mail. smtpclient class is used to set SMTP and then send the mail.

 

Using system. net. Mail; // namespace

 

Smtpclient _ smtpclient = new smtpclient (); // SMTP verification class

_ Smtpclient. deliverymethod = smtpdeliverymethod. Network; // specify the email sending Method
_ Smtpclient. Host = "SMTP server address"; // specify the SMTP server
_ Smtpclient. Credentials = new system. net. networkcredential ("username", "password ");

 

Mailmessage _ mailmessage = new mailmessage ("'email address", "recipient email ");
_ Mailmessage. Subject = "title"; // subject
_ Mailmessage. Body = "content"; // content
_ Mailmessage. bodyencoding = system. Text. encoding. utf8; // body Encoding
_ Mailmessage. isbodyhtml = true; // set it to HTML Format
_ Mailmessage. Priority = mailpriority. High; // priority

 

_ Smtpclient. Send (_ mailmessage); // send an email

 

OK @!!!!!!!!!!

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.