ASP. NET 2.0 email sending code

Source: Internet
Author: User
Tags mailmessage smtpclient

In the past two days, you need to create a webpage that collects information submitted by users and then sends an email to the specified email address. You can use the class below system. net. Mail to send emails in Asp.net 2.0. The http://www.systemnetmail.com/faq/2.1.aspx address is written by the author of system. net. Mail as if it is similar to msdn FAQ, seeCodeYou can refer to the following. Don't talk about anything. paste the code below. After all, the Code is the most important:

1 Protected   Void Btnsend_click ( Object Sender, eventargs E)
2 {
3 Mailmessage =   New Mailmessage ();
4 String Strbody;
5
6 Mailmessage. From =   New Mailaddress ( " 365rss@gmail.com " );
7 Mailmessage. to. Add ( " Prlibertine@gmail.com " );
8 Mailmessage. Subject =   " 365rss. cn " ;
9
10 Strbody =   " <H2> "   + Ddlmaintag. selecteditem. Text +   " </H2> <br> " ;
11 Strbody + =   " <H4> "   + Tbtag. Text +   " </H4> <br> <HR> <br> " ;
12 Strbody + =   " · "   + Tbadv. text;
13
14 Sendmail (mailmessage );
15 }
16
17 // Sendmail
18 Private   Void Sendmail (mailmessage Mail)
19 {
20 Smtpclient =   New Smtpclient ();
21 Smtpclient. enablessl =   True ;
22 Smtpclient. Host =   " Smtp.gmail.com " ;
23 Smtpclient. Port =   465 ;
24 Smtpclient. Credentials =   New Networkcredential ( " 365rss@gmail.com " , " PWD " );
25 Try
26 {
27Smtpclient. Send (Mail );
28Label1.text= "OK";
29}
30 Catch
31 {
32Label1.text= "False";
33}
34 }
35

 

 

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.