Asp.net MVC sends an email

Source: Internet
Author: User
Tags smtpclient

@ Try {
System. Net. Mail. MailAddress from = new System. Net. Mail. MailAddress ("www.2cto.com", "ethan"); // enter the email address and display name.

System. Net. Mail. MailAddress to = new System. Net. Mail. MailAddress (www.2cto.com, "jimmy"); // enter the email recipient address and name.
// Set the Sending address and Receiving address. The Receiving address can be multiple
System. Net. Mail. MailMessage mail = new System. Net. Mail. MailMessage ();
Mail. From = from;
Mail. To. Add ();
Mail. Subject = "topic content ";
Mail. Body = "hello ";
Mail. IsBodyHtml = true; // set to display htmls
// Set the mail service address
System. Net. Mail. SmtpClient client = new System. Net. Mail. SmtpClient ();
Client. Host = "smtp.163.com ";
// Enter the user name and password related to the server address
Client. Credentials = new System. Net. NetworkCredential ("www.2cto.com ","******");
// Send an email
Client. Send (mail );
}
Catch {
@: <B> failed to send </B>
}
Author: Cai_Ethan

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.