ASP.net 2.0 code to send mail

Source: Internet
Author: User
Tags mail mailmessage smtpclient
asp.net| Send mail

These two days because you want to do a Web page that collects user submissions and then sends messages to a specific mailbox. To send a message inside asp.net 2.0, you can use the System.Net.Mail class below. Http://www.systemnetmail.com/faq/2.1.aspx This address is written by a System.Net.Mail author as if it were an MSDN-like FAQ, which you can refer to when looking at the code. Do not say anything, the following post code it, after all, the code is the most important:

1protected void Btnsend_click (object sender, EventArgs e)
2 {
3 MailMessage 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
Ten strbody = "One strbody + + "Strbody + + + Tbadv.text;
13
SendMail (MailMessage);
15}
16
//sendmail
private void SendMail (MailMessage mail)
19 {
SmtpClient smtpclient = new SmtpClient ();
Smtpclient.enablessl = true;
Smtpclient.host = "smtp.gmail.com";
Smtpclient.port = 465;
Smtpclient.credentials = new NetworkCredential ("365rss@gmail.com", "pwd");
Try
26 {
Smtpclient.send (mail);
Label1.Text = "OK";
29}
Catch
31 {
Label1.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.