<div>
Send e-mail demo
<table cellpadding= "0" cellspacing= "0" border= "0" style= "font-family: Song body, Arial, Helvetica, Sans-serif;
font-size:15px; width:411px; " >
<tr>
<TD class= "Style5" >
e-mail address:
</td>
<TD class= "Style6" >
<asp:textbox id= "Tb_email" runat= "Server" width= "269px" ></asp:TextBox>
</td>
</tr>
<tr>
<TD class= "Style5" >
CC to:
</td>
<TD class= "Style6" >
<asp:textbox id= "TB_CC" runat= "Server" width= "268px" ></asp:TextBox>
</td>
</tr>
<tr>
<TD class= "Style5" >
Message Subject:
</td>
<TD class= "Style6" >
<asp:textbox id= "Tb_subject" runat= "Server" width= "268px" ></asp:TextBox>
</td>
</tr>
<tr>
<TD class= "Style5" >
Message content:
</td>
<TD class= "Style6" >
<asp:textbox id= "Tb_body" runat= "Server" height= "63px" textmode= "MultiLine" width= "266px" ></asp:textbox >
</td>
</tr>
<tr>
<TD class= "Style5" >
To add an attachment:
</td>
<TD class= "Style6" >
<asp:fileupload id= "tb_attachment" runat= "Server" width= "265px"/>
</td>
</tr>
<tr>
<TD align= "Right" colspan= "2" >
<asp:button id= "Btn_sendemail" runat= "Server" text= "Send Mail"
onclick= "Btn_sendemail_click"/>
</td>
</tr>
</table>
</div>
Back-End Code:
protected void Btn_sendemail_click (object sender, EventArgs e)
{
Declaring a Mail object
MailMessage mymail = new MailMessage ();
Sender Address
As yourself, enter your own mailbox here
MyMail. from = new MailAddress ("[email protected]");
Recipient address
MyMail. To.add (New MailAddress (Tb_email.text));
Message subject
MyMail. Subject = Tb_subject.text;
Message header Encoding
MyMail. subjectencoding = System.Text.Encoding.UTF8;
Send the contents of a message
MyMail. Body = Tb_body.text;
Message content Encoding
MyMail. bodyencoding = System.Text.Encoding.UTF8;
Add an attachment
Attachment myfiles = new Attachment (tb_Attachment.PostedFile.FileName);
MyMail. Attachments.Add (myfiles);
CC to another mailbox
MyMail. Cc. ADD (New MailAddress (TB_CC). Text));
Whether it is an HTML message
MyMail. Isbodyhtml = true;
Message priority
MyMail. priority = Mailpriority.high;
Create a mail server class
SmtpClient myclient = new SmtpClient ();
MyClient. Host = "smtp.163.com";
SMTP Service port
MyClient. Port = 25;
Verify Login
MyClient. Credentials = new NetworkCredential ("", "* * * * *");//"@" Enter a valid message name, "*" Enter a valid password
MyClient. Send (MyMail);
}
ASP. NET WebForm send e-mail