这两天因为要做一个可以收集用户提交信息,然后发送邮件到指定邮箱的网页。在 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
新闻热点
疑难解答
图片精选