ASP. NET Mail System. Net. Mail

Source: Internet
Author: User
Tags mailmessage smtpclient

• SendEmail. aspx code on the front-end page
1 2 send email demo
3 4 <table cellpadding = "0" cellspacing = "0" border = "0" style = "font-family:, Arial, Helvetica, sans-serif;
5 font-size: 15px; width: 411px; ">
6 <tr>
7 <td class = "style5">
8. Email address:
9 </td>
10 <td class = "style6">
11 <asp: TextBox ID = "tb_Email" runat = "server" Width = "269px"> </asp: TextBox>
12 </td>
13 </tr>
14 <tr>
15 <td class = "style5">
16 CC:
17 </td>
18 <td class = "style6">
19 <asp: TextBox ID = "tb_cc" runat = "server" Width = "268px"> </asp: TextBox>
20 </td>
21 </tr>
22 <tr>
23 <td class = "style5">
24 Email Subject:
25 </td>
26 <td class = "style6">
27 <asp: TextBox ID = "tb_Subject" runat = "server" Width = "268px"> </asp: TextBox>
28 </td>
29 </tr>
30 <tr>
31 <td class = "style5">
32 email content:
33 </td>
34 <td class = "style6">
35 <asp: TextBox ID = "tb_Body" runat = "server" Height = "63px" TextMode = "MultiLine" Width = "266px"> </asp: TextBox>
36 </td>
37 </tr>
38 <tr>
39 <td class = "style5">
40 add attachments:
41 </td>
42 <td class = "style6">
43 <asp: FileUpload ID = "tb_Attachment" runat = "server" Width = "265px"/>
44 </td>
45 </tr>
46 <tr>
47 <td align = "right" colspan = "2">
48 <asp: Button ID = "btn_SendEmail" runat = "server" Text = "Send email" OnClick = "btn_SendEmail_Click"/>
49 </td>
50 </tr>
51 </table>

• Background SendEmail. aspx. cs code
1 protected void btn_SendEmail_Click (object sender, EventArgs e)
2 {
3 // declare a Mail object
4 MailMessage mymail = new MailMessage ();
5 // sender address
6 // if you are yourself, enter your email address here
7 mymail. From = new MailAddress ("15510180880@163.com ");
8 // recipient address
9 mymail. To. Add (new MailAddress (tb_Email.Text ));
10 // Email Subject
11 mymail. Subject = tb_Subject.Text;
12 // email title Encoding
13 mymail. SubjectEncoding = System. Text. Encoding. UTF8;
14 // content of the email
15 mymail. Body = tb_Body.Text;
16 // email Content Encoding
17 mymail. BodyEncoding = System. Text. Encoding. UTF8;
18 // Add an attachment
19 Attachment myfiles = new Attachment (tb_Attachment.PostedFile.FileName );
20 mymail. Attachments. Add (myfiles );
21 // CC to another email address
22 mymail. CC. Add (new MailAddress (tb_cc.Text ));
23 // whether it is an HTML email
24 mymail. IsBodyHtml = true;
25 // email priority: www.2cto.com
26 mymail. Priority = MailPriority. High;
27 // create an email server class
28 SmtpClient myclient = new SmtpClient ();
29 myclient. Host = "SMTP.163.com ";
30 // SMTP Service port
31 myclient. Port = 25;
32 // verify Logon
33. myclient. credentials = new NetworkCredential ("@", "*****"); // "@" enter a valid Email name, "*" enter a valid Password
34 myclient. Send (mymail );
35}

• The results are as follows:
3.1 fill in items and click send email



3.2 and 163 email addresses.

 


 

3.3, QQ mailbox.





From XuebinDing
 

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.