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.