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
13
public
partial
class
_Default : System.Web.UI.Page
14
{
15
protected void Button1_Click(object sender, EventArgs e)
16
{
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
21
SmtpClient smtp = new SmtpClient("smtp.vs2005.com");
22
smtp.Credentials = new MailCredential("username", "userpassword");
23
smtp.Send(message);
24
}
25
}
26
27
public
class
MailCredential : ICredentialsByHost
28
{
29
string username = "";
30
string userpwd = "";
31
32
public MailCredential(string un, string pwd)
33
{
34
username = un;
35
userpwd = pwd;
36
}
37
38
ICredentialsByHost Members#region ICredentialsByHost Members
39
40
public NetworkCredential GetCredential(string host, int port, string authenticationType)
41
{
42
NetworkCredential nc = new NetworkCredential(username, userpwd);
43
return nc;
44
}
45
46
#endregion
47
}
48

2

3

4

5

6

7

8

9

10

11

12

13

14



15

16



17

18

19

20

21

22

23

24

25

26

27

28



29

30

31

32

33



34

35

36

37

38


39

40

41



42

43

44

45

46

47

48
