In the past two days, I have been working on a web page that can collect user submitted information and then send emails to designated mailboxes. To send emails in asp.net 2.0, you can use the following classes of System.Net.Mail. At the address http://www.systemnetmail.com/faq/2.1.aspx, the author of System.Net.Mail seems to have written a FAQ similar to MSDN. You can refer to the following when looking at the code. Without further ado, let’s post the code below. 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(" [email protected] ");
7 mailMessage.To.Add(" [email protected] ");
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 smtpClient = new SmtpClient();
21 smtpClient.EnableSsl = true;
22 smtpClient.Host = "smtp.gmail.com";
23 smtpClient.Port = 465;
24 smtpClient.Credentials = new NetworkCredential(" [email protected] ", "pwd");
25 try
26 {
27 smtpClient.Send(mail);
28 Label1.Text = "ok";
29 }
30 catch
31 {
32 Label1.Text = "false";
33}
34}
35
http://www.cnblogs.com/jessezhao/archive/2007/01/16/621946.html