. Net advanced learning: Using ASP. NET to send emails

Source: Internet
Author: User
Tags mailmessage smtpclient

If your ASP. NETProgramI have learned a lot and want to use ASP. NET to send emails.ArticleNo matter how it is implemented on the Internet, the following two methods for sending. Net emails are provided for your reference, which is very simple.

First:

1. configuration file (Web. config) + A small amount of C #Code

In Configuration Add under Node

  <  System.net  >  
< Mailsettings >
< SMTP from = " Baidu@163.com " >
< Network host = " Smtp.163.com " Password = " Baidu " Port = " 25 " Username = " Baidu " Defaultcredentials = " False " />
</ SMTP >
</ Mailsettings >
</ System.net >
  ///     <Summary>  
/// Send email
/// </Summary>
Private Void Sendmail ()
{
System. net. Mail. mailmessage message = New System. net. Mail. mailmessage ();
Message. From = New System. net. Mail. mailaddress ( " Baidu@163.com " ); // The sender's email address, which is consistent with the from Value in the SMTP node.
Message. to. Add ( New System. net. Mail. mailaddress ( " Taobao@163.com " )); // Recipient's email address
Message. Subject = " Hello " ;
Message. Body = " <B> Taobao </B> " ;
Message. isbodyhtml = True ;

System. net. Mail. smtpclient = New System. net. Mail. smtpclient ();
Smtpclient. Send (Message );
}

Okay. The first method for sending emails is described below.

  ///     <Summary>  
/// Send email
/// </Summary>
Private Void Sendmail ()
{
System. net. Mail. mailmessage message = New System. net. Mail. mailmessage ();
Message. From = New System. net. Mail. mailaddress ( " Baidu@163.com " ); // The sender's email address, which is consistent with the from Value in the SMTP node.
Message. to. Add ( New System. net. Mail. mailaddress ( " Taobao@163.com " )); // Recipient's email address
Message. Subject = " Hello " ;
Message. Body = " <B> Taobao </B> " ;
Message. isbodyhtml = True ;

System. net. Mail. smtpclient = New System. net. Mail. smtpclient ( " Smtp.163.com " , 25 );
Smtpclient. Credentials = New System. net. networkcredential ( " Baidu " , " Baidu " ); // The parameters are the email user name and password respectively.
Smtpclient. Send (Message );
}

 

The above two methods are easy to send emails.

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.