1 Using System;
2 Using System. Data;
3 Using System. configuration;
4 Using System. collections;
5 Using System. Web;
6 Using System. Web. Security;
7 Using System. Web. UI;
8 Using System. Web. UI. webcontrols;
9 Using System. Web. UI. webcontrols. webparts;
10 Using System. Web. UI. htmlcontrols;
11 Using System. Web. mail;
12
13 Public Class Sendmail
14 {
15 String Tb_from;
16 String Tb_to;
17 String Tb_mailbody;
18 String Tb_smtpserver;
19 String Tb_body;
20 String Tb_sub;
21 Public Sendmail ( String To, String Body, String Sub)
22 {
23Tb_to=To. Trim ();
24Tb_body=Body. Trim ();
25Tb_sub=Sub. Trim ();
26}
27
28 Public Void Sengmill_net ()
29 {
30 Tb_from = " Xxxx@21cn.com " ;
31 Tb_mailbody = Tb_body;
32 Tb_smtpserver = " Smtp.21cn.com " ;
33 System. Web. Mail. mailmessage mailmsg = New System. Web. Mail. mailmessage ();
34 Mailmsg. From = Tb_from;
35 Mailmsg. = Tb_to;
36 Mailmsg. Body = Tb_mailbody;
37 Mailmsg. Subject = Tb_sub;
38 Mailmsg. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate " , " 1 " );
39 // Whether verification is required. Generally, verification is required.
40 Mailmsg. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/sendusername " , " XXXXX " );
41 // User name in your mailbox
42 Mailmsg. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/sendpassword " , " XXXXX " );
43 // Password of your mailbox
44 System. Web. Mail. smtpmail. smtpserver = Tb_smtpserver;
45 System. Web. Mail. smtpmail. Send (mailmsg );
46 }
47 }
48
49 Public Partial Class Bank: system. Web. UI. Page
50 {
51 Protected Void Page_load ( Object Sender, eventargs E)
52 {
53
54}
55 Protected Void Btnsend_click ( Object Sender, eventargs E)
56
57 {
58 /**/ ////Call code
59 Sendmail t = New Sendmail (xxx@xxx.com, " Text Content " , " Title content " );
60 T. sengmill_net ();
61 }
62 }