ASP. NET source code for sending emails

Source: Internet
Author: User
Tags mailmessage smtpclient
UsingSystem. Collections. Generic;
 
UsingSystem. text;
UsingSystem. net;
 
UsingSystem. net. mail;Try
{
 
// The code must be gb2312.
Encoding encoding = encoding. getencoding (936 );
 
Mailmessage message =NewMailmessage (
  New  mailaddress (" your mailbox ", " 5 ", encoding),  // The first is the sender's address, the second parameter is the sender  
NewMailaddress (textbox1.text ));// Recipient's email
 
Message. subjectencoding = encoding;
Message. Subject = textbox2.text;// Title
 
Message. bodyencoding = encoding;
 message. body = textbox3.text;  // subject  
 smtpclient =  New  smtpclient (" smtp.163.com ");  // mailbox server  
 smtpclient. credentials =  New  networkcredential (" your mailbox username ", " your mailbox password " );  // user name and password of the mailbox  
Smtpclient. Timeout = 999999;
 
Smtpclient. Send (Message );
}
 
Catch(Exception ex)
{
 
Throw NewException (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.