這兩天因為要做一個可以收集用戶提交信息,然後發送郵件到指定郵箱的網頁。在 asp.net 2.0 裡面發送郵件可以使用 System.Net.Mail 下面的類。http://www.systemnetmail.com/faq/2.1.ASPx 這個地址有 System.Net.Mail 的作者寫的仿佛是 MSDN 類似的 Faq,看代碼的時候可以參考以下。什麼都不說了,下面貼出來代碼吧,畢竟代碼是最重要的:
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
轉自:動態網站制作指南 | www.knowsky.com