Asp. Net how to send mail, asp.net send mail

Source: Internet
Author: User
Tags how to send mail mailmessage net send smtpclient

Asp. Net how to send mail, asp.net send mail

/// <Summary> /// send an email to the user /// </summary> /// <param name = "email"> User's email address </param> // /<param name = "activecode"> activation code </param> public void sendEmail (string email, string activecode, int userId) {// The first thing to declare is: before using this method, make sure that the SMTP service of the sender's mailbox is enabled !!!! Otherwise, an error is reported! // Email is the target email address MailMessage mailMsg = new MailMessage (); // two classes. Do not mix them. Introduce System. net Assembly mailMsg. from = new MailAddress ("Email address", "sender name (can be blank)"); // source Email address, sender Email mailMsg. to. add (new MailAddress (email); // target email address. There can be multiple recipients mailMsg. Subject = "sample, hello! "; // The Mail title string url =" <a href =' http://localhost:8899/ashx/Active.ashx?userId= "+ UserId +" & code = "+ activecode +" '> Click Activate </a> "; mailMsg. body = url; // the content of the sent Email mailMsg. isBodyHtml = true; // Let the mailbox parse the content SmtpClient client = new SmtpClient ("smtp.sina.cn"); // define the SMTP server smtp.163.com and smtp.qq.com client used by the sender. credentials = new NetworkCredential ("name", "pwd"); // specify the user name and password of the sender's mailbox client. send (mailMsg); // Send the mail content to the SMTP server .}

  

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.