The example of this article describes the implementation of ASP.net sending mail. Share to everyone for your reference. The implementation methods are as follows:
MailMessage MAILMSG = new MailMessage ();
Set the recipient's e-mail address
mailmsg.to = "bailichunwow@qq.com";
Set the sender's e-mail address
Mailmsg.from = "bailichun@vip.qq.com";
Set Message subject
Mailmsg.subject = "Test";
Set up message content
Mailmsg.body = "Content";
Mailmsg.bodyformat = Mailformat.text;
mailmsg.priority = Mailpriority.normal;
Try
{
Setting up a Send mail server
Smtpmail.smtpserver = "localhost";
Send mail
Smtpmail.send (MAILMSG);
}
Catch
{
}
A complete Send mail code
Mailobj _mail = new Mailobj ();
_mail.sendmail ("lxx@qq.com", "Test", "<b> content </b>");
_mail. Dispose ();
Core code
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Collections.Generic;
Using System.Net.Mail;
Using System.Text;
Namespace EC
{
<summary>
Send mail
</summary>
public class Mailobj
{
private string _strhost = String. Empty;
private string _straccount = String. Empty;
private string _strpwd = String. Empty;
private string _strfrom = String. Empty;
#region Construction and destructor function
Public Mailobj ()
{
_strhost = "smtp.163.com"; STMP server Address
_straccount = "AA"; SMTP Service Account
_strpwd = "123456"; SMTP Service password
_strfrom = "aa@163.com"; Mailing address of sending party
}
<summary>
Send mail purchase function
</summary>
<param name= "Strhost" >stmp server address:smtp.163.com</param>
<param name= "Straccount" >SMTP service account:liugongxun</param>
<param name= "strpwd" >smtp service password:123456</param>
<param name= "Strfrom" > Sender email Address:liugongxun@163.com</param>
Public Mailobj (String strhost, String Straccount, String strpwd, String strfrom)
{
_strhost = Strhost;
_straccount = Straccount;
_strpwd = strpwd;
_strfrom = Strfrom;
}
~mailobj ()
{
Dispose ();
}
public void Dispose ()
{
Gc. SuppressFinalize (this);
}
#endregion
#region Send mail
public bool SendMail (string to, string title, string content)
{
SmtpClient _smtpclient = new SmtpClient ();
_smtpclient.deliverymethod = smtpdeliverymethod.network;//Specify how e-mail is sent
_smtpclient.host = _strhost;//Specify SMTP server
_smtpclient.credentials = new System.Net.NetworkCredential (_straccount, _strpwd);//username and password
MailMessage _mailmessage = new MailMessage (_strfrom, to);
_mailmessage.subject = title;//Theme
_mailmessage.body = content;//Content
_mailmessage.bodyencoding = system.text.encoding.utf8;//Body encoding
_mailmessage.isbodyhtml = true;//set to HTML format
_mailmessage.priority = mailpriority.high;//Priority
Try
{
_smtpclient.send (_mailmessage);
return true;
}
Catch
{
return false;
}
}
#endregion
}
}
I hope this article will help you with the ASP.net program design.