ASP. NET WebForm send e-mail

Source: Internet
Author: User
Tags mailmessage smtpclient

<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>
&LT;TD class= "Style5" >
e-mail address:
</td>
&LT;TD class= "Style6" >
<asp:textbox id= "Tb_email" runat= "Server" width= "269px" ></asp:TextBox>
</td>
</tr>
<tr>
&LT;TD class= "Style5" >
CC to:
</td>
&LT;TD class= "Style6" >
<asp:textbox id= "TB_CC" runat= "Server" width= "268px" ></asp:TextBox>
</td>
</tr>
<tr>
&LT;TD class= "Style5" >
Message Subject:
</td>
&LT;TD class= "Style6" >
<asp:textbox id= "Tb_subject" runat= "Server" width= "268px" ></asp:TextBox>
</td>
</tr>
<tr>
&LT;TD class= "Style5" >
Message content:
</td>
&LT;TD class= "Style6" >
<asp:textbox id= "Tb_body" runat= "Server" height= "63px" textmode= "MultiLine" width= "266px" ></asp:textbox >
</td>
</tr>
<tr>
&LT;TD class= "Style5" >
To add an attachment:
</td>
&LT;TD class= "Style6" >
<asp:fileupload id= "tb_attachment" runat= "Server" width= "265px"/>
</td>
</tr>
<tr>
&LT;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

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.