Example of ASP. NET source code for sending emails

Source: Internet
Author: User
Tags mailmessage smtpclient

Using System. collections. generic; using System. text; using System. net; using System. net. mail; try {// The Encoding must be GB2312 encoding Encoding = Encoding. getEncoding (936); MailMessage Message = new MailMessage (new MailAddress ("your mailbox", "5", encoding), // The first is the sender's address, the second parameter is the sender's new MailAddress (TextBox1.Text); // recipient's email Message. subjectEncoding = encoding; Message. subject = TextBox2.Text; // The title Message. bodyEncoding = encoding; Message. body = TextBox3.Text; // subject SmtpClient smtpClient = new SmtpClient ("smtp.163.com"); // Mail Server smtpClient. credentials = new NetworkCredential ("your mailbox username", "Your mailbox password"); // the username and password of the mailbox smtpClient. timeout = 999999; smtpClient. send (Message);} catch (Exception ex) {throw new Exception (ex. message );}

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.