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 @!!!!!!!!!!