1 private void SentEmail(string email,string name,string UserAccount)
2 {
3 BLL.MailSender ms = new MailSender();
4 ms.Body = "尊敬的"+name+":<br><br>"+"       欢迎使用********!(<a href='http://*********.com'>http://*********</a>)<br><br>       您注册的账号现已开通!登陆名:"
5 +UserAccount+"";
6 ms.From = "********";
7 ms.Password = "********";
8 ms.Port = "25";
9 ms.Server = "*********";
10 ms.Subject = "账号开通信息";
11 ms.To = email;
12 ms.UserName = "*********";
13 ms.SendMail();
14
15 }
16
2 {
3 BLL.MailSender ms = new MailSender();
4 ms.Body = "尊敬的"+name+":<br><br>"+"       欢迎使用********!(<a href='http://*********.com'>http://*********</a>)<br><br>       您注册的账号现已开通!登陆名:"
5 +UserAccount+"";
6 ms.From = "********";
7 ms.Password = "********";
8 ms.Port = "25";
9 ms.Server = "*********";
10 ms.Subject = "账号开通信息";
11 ms.To = email;
12 ms.UserName = "*********";
13 ms.SendMail();
14
15 }
16
1using System;
2using System.Web.Mail;
3using CDO;
4namespace BLL
5{
6 /// <summary>
7 /// MailSender 的摘要说明。
8 /// </summary>
9
10 public class MailSender
11 {
12
13 private string server = "";
14 /// <summary>
15 ///
16 /// </summary>
17 public string Server
18 {
19 get
20 {
21 return server;
22 }
23 set
24 {
25 if (value != server) server = value;
26 }
27 }
28
29 private string port = "";
30 /// <summary>
31 ///
32 /// </summary>
33 public string Port
34 {
35 get
36 {
37 return port;
38 }
39 set
40 {
41 if (value != port) port = value;
42 }
43 }
44
45 private string userName = "";
46 /// <summary>
47 /// 用户名 [如果需要身份验证的话]
48 /// </summary>
49 public string UserName
50 {
51 get
52 {
53 return userName;
54 }
55 set
56 {
57 if (value != userName)
58 userName = value;
59 }
60 }
61
62 private string password = "";
63 /// <summary>
64 /// 密码 [如果需要身份验证的话]
65 /// </summary>
66 public string Password
67 {
68 get
69 {
70 return password;
71 }
72 set
73 {
74 if (value != password)
75 password = value;
76 }
77 }
78
79 private string from = "";
80 /// <summary>
81 /// 发件人地址
82 /// </summary>
83 public string From
84 {
85 get
86 {
87 return from;
88 }
89 set
90 {
91 if (value != from)
92 from = value;
93 }
94 }
95
96 private string to = "";
97 /// <summary>
98 /// 收件人地址
99 /// </summary>
100 public string To
101 {
102 get
103 {
104 return to;
105 }
106 set
107 {
108 if (value != to)
109 to = value;
110 }
111 }
112
113 private string subject = "";
114 /// <summary>
115 /// 邮件的主题
116 /// </summary>
117 public string Subject
118 {
119 get
120 {
121 return subject;
122 }
123 set
124 {
125 if (value != subject)
126 subject = value;
127 }
128 }
129
130
131 private string body = "";
132 /// <summary>
133 /// 邮件正文
134 /// </summary>
135 public string Body
136 {
137 get
138 {
139 return body;
140 }
141 set
142 {
143 if (value != body)
144 body = value;
145 }
146 }
147
148
149 private string htmlBody = "";
150 /// <summary>
151 /// 超文本格式的邮件正文
152 /// </summary>
153 public string HtmlBody
154 {
155 get
156 {
157 return htmlBody;
158 }
159 set
160 {
161 if (value != htmlBody)
162 htmlBody = value;
163 }
164 }
165
166 private bool isHtml = false;
167 /// <summary>
168 /// 是否是html格式的邮件
169 /// </summary>
170 public bool IsHtml
171 {
172 get
173 {
174 return isHtml;
175 }
176 set
177 {
178 if (value != isHtml)
179 isHtml = value;
180 }
181 }
182
183
184 public void SendMail ()
185 {
186 MailMessage msg = new MailMessage();
187
188 msg.From = from;
189 msg.To = to;
190 msg.Subject = subject;
191 msg.Body = body;
192 msg.BodyFormat = MailFormat.Html;
193 msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1" );
194 msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",userName);
195 msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
196
197 msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", port);
198
199 //msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "1");
200
201
202 SmtpMail.SmtpServer = server;
203 SmtpMail.Send(msg);
204
205
206
207 }
208 }
209}
210
2using System.Web.Mail;
3using CDO;
4namespace BLL
5{
6 /// <summary>
7 /// MailSender 的摘要说明。
8 /// </summary>
9
10 public class MailSender
11 {
12
13 private string server = "";
14 /// <summary>
15 ///
16 /// </summary>
17 public string Server
18 {
19 get
20 {
21 return server;
22 }
23 set
24 {
25 if (value != server) server = value;
26 }
27 }
28
29 private string port = "";
30 /// <summary>
31 ///
32 /// </summary>
33 public string Port
34 {
35 get
36 {
37 return port;
38 }
39 set
40 {
41 if (value != port) port = value;
42 }
43 }
44
45 private string userName = "";
46 /// <summary>
47 /// 用户名 [如果需要身份验证的话]
48 /// </summary>
49 public string UserName
50 {
51 get
52 {
53 return userName;
54 }
55 set
56 {
57 if (value != userName)
58 userName = value;
59 }
60 }
61
62 private string password = "";
63 /// <summary>
64 /// 密码 [如果需要身份验证的话]
65 /// </summary>
66 public string Password
67 {
68 get
69 {
70 return password;
71 }
72 set
73 {
74 if (value != password)
75 password = value;
76 }
77 }
78
79 private string from = "";
80 /// <summary>
81 /// 发件人地址
82 /// </summary>
83 public string From
84 {
85 get
86 {
87 return from;
88 }
89 set
90 {
91 if (value != from)
92 from = value;
93 }
94 }
95
96 private string to = "";
97 /// <summary>
98 /// 收件人地址
99 /// </summary>
100 public string To
101 {
102 get
103 {
104 return to;
105 }
106 set
107 {
108 if (value != to)
109 to = value;
110 }
111 }
112
113 private string subject = "";
114 /// <summary>
115 /// 邮件的主题
116 /// </summary>
117 public string Subject
118 {
119 get
120 {
121 return subject;
122 }
123 set
124 {
125 if (value != subject)
126 subject = value;
127 }
128 }
129
130
131 private string body = "";
132 /// <summary>
133 /// 邮件正文
134 /// </summary>
135 public string Body
136 {
137 get
138 {
139 return body;
140 }
141 set
142 {
143 if (value != body)
144 body = value;
145 }
146 }
147
148
149 private string htmlBody = "";
150 /// <summary>
151 /// 超文本格式的邮件正文
152 /// </summary>
153 public string HtmlBody
154 {
155 get
156 {
157 return htmlBody;
158 }
159 set
160 {
161 if (value != htmlBody)
162 htmlBody = value;
163 }
164 }
165
166 private bool isHtml = false;
167 /// <summary>
168 /// 是否是html格式的邮件
169 /// </summary>
170 public bool IsHtml
171 {
172 get
173 {
174 return isHtml;
175 }
176 set
177 {
178 if (value != isHtml)
179 isHtml = value;
180 }
181 }
182
183
184 public void SendMail ()
185 {
186 MailMessage msg = new MailMessage();
187
188 msg.From = from;
189 msg.To = to;
190 msg.Subject = subject;
191 msg.Body = body;
192 msg.BodyFormat = MailFormat.Html;
193 msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1" );
194 msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",userName);
195 msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
196
197 msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", port);
198
199 //msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "1");
200
201
202 SmtpMail.SmtpServer = server;
203 SmtpMail.Send(msg);
204
205
206
207 }
208 }
209}
210