1
using
System;
2
using
System.Data;
3
using
System.Configuration;
4
using
System.Web;
5
using
System.Web.Security;
6
using
System.Web.UI;
7
using
System.Web.UI.WebControls;
8
using
System.Web.UI.WebControls.WebParts;
9
using
System.Web.UI.HtmlControls;
10
using
System.Net.Mail;
11
using
System.Net;
12![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
13
public
partial
class
_Default : System.Web.UI.Page
14![](https://i-blog.csdnimg.cn/blog_migrate/6c19eed907fa3975a50d756ba6721e21.png)
{
15
protected void Button1_Click(object sender, EventArgs e)
16![](https://i-blog.csdnimg.cn/blog_migrate/5e5d4bfadfdacb2f3d631c8c1638617c.png)
{
17
MailMessage message = new MailMessage("support@vs2005.com", "to@domain.com");
18
message.Subject = "hello!";
19
message.Body = "this is a mail from vs2005.com";
20![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
21
SmtpClient smtp = new SmtpClient("smtp.vs2005.com");
22
smtp.Credentials = new MailCredential("username", "userpassword");
23
smtp.Send(message);
24
}
25
}
26![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
27
public
class
MailCredential : ICredentialsByHost
28![](https://i-blog.csdnimg.cn/blog_migrate/6c19eed907fa3975a50d756ba6721e21.png)
{
29
string username = "";
30
string userpwd = "";
31![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
32
public MailCredential(string un, string pwd)
33![](https://i-blog.csdnimg.cn/blog_migrate/5e5d4bfadfdacb2f3d631c8c1638617c.png)
{
34
username = un;
35
userpwd = pwd;
36
}
37![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
38![](https://i-blog.csdnimg.cn/blog_migrate/283eb36683791455138dde6128176eea.png)
ICredentialsByHost Members#region ICredentialsByHost Members
39![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
40
public NetworkCredential GetCredential(string host, int port, string authenticationType)
41![](https://i-blog.csdnimg.cn/blog_migrate/5e5d4bfadfdacb2f3d631c8c1638617c.png)
{
42
NetworkCredential nc = new NetworkCredential(username, userpwd);
43
return nc;
44
}
45![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
46
#endregion
47
}
48
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
2
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
3
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
4
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
5
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
6
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
7
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
8
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
9
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
10
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
11
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
12
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
13
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
14
![](https://i-blog.csdnimg.cn/blog_migrate/6c19eed907fa3975a50d756ba6721e21.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6af27ecd107be99c65dc9b76d15cc129.png)
![](https://i-blog.csdnimg.cn/blog_migrate/25b9ba110d48991afa260c8953a12c67.png)
15
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
16
![](https://i-blog.csdnimg.cn/blog_migrate/5e5d4bfadfdacb2f3d631c8c1638617c.png)
![](https://i-blog.csdnimg.cn/blog_migrate/283eb36683791455138dde6128176eea.png)
![](https://i-blog.csdnimg.cn/blog_migrate/25b9ba110d48991afa260c8953a12c67.png)
17
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
18
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
19
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
20
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
21
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
22
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
23
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
24
![](https://i-blog.csdnimg.cn/blog_migrate/ba4c970bbec3e8795206d8a609d20921.png)
25
![](https://i-blog.csdnimg.cn/blog_migrate/cc27d5af14287d1aad3c1fefe4c5dbf4.png)
26
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
27
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)
28
![](https://i-blog.csdnimg.cn/blog_migrate/6c19eed907fa3975a50d756ba6721e21.png)
![](https://i-blog.csdnimg.cn/blog_migrate/6af27ecd107be99c65dc9b76d15cc129.png)
![](https://i-blog.csdnimg.cn/blog_migrate/25b9ba110d48991afa260c8953a12c67.png)
29
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
30
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
31
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
32
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
33
![](https://i-blog.csdnimg.cn/blog_migrate/5e5d4bfadfdacb2f3d631c8c1638617c.png)
![](https://i-blog.csdnimg.cn/blog_migrate/283eb36683791455138dde6128176eea.png)
![](https://i-blog.csdnimg.cn/blog_migrate/25b9ba110d48991afa260c8953a12c67.png)
34
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
35
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
36
![](https://i-blog.csdnimg.cn/blog_migrate/ba4c970bbec3e8795206d8a609d20921.png)
37
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
38
![](https://i-blog.csdnimg.cn/blog_migrate/283eb36683791455138dde6128176eea.png)
![](https://i-blog.csdnimg.cn/blog_migrate/5e5d4bfadfdacb2f3d631c8c1638617c.png)
39
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
40
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
41
![](https://i-blog.csdnimg.cn/blog_migrate/5e5d4bfadfdacb2f3d631c8c1638617c.png)
![](https://i-blog.csdnimg.cn/blog_migrate/283eb36683791455138dde6128176eea.png)
![](https://i-blog.csdnimg.cn/blog_migrate/25b9ba110d48991afa260c8953a12c67.png)
42
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
43
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
44
![](https://i-blog.csdnimg.cn/blog_migrate/ba4c970bbec3e8795206d8a609d20921.png)
45
![](https://i-blog.csdnimg.cn/blog_migrate/2cc9face5c8a311e59dd7aa1cbd813d6.png)
46
![](https://i-blog.csdnimg.cn/blog_migrate/ba4c970bbec3e8795206d8a609d20921.png)
47
![](https://i-blog.csdnimg.cn/blog_migrate/cc27d5af14287d1aad3c1fefe4c5dbf4.png)
48
![](https://i-blog.csdnimg.cn/blog_migrate/755e10718fc98b9fda4ecb7319a8925f.png)