1using System;
2using System.Data;
3using System.Configuration;
4using System.Web;
5using System.Web.Security;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8using System.Web.UI.WebControls.WebParts;
9using System.Web.UI.HtmlControls;
10using System.Net.Mail;
11using System.Net;
12
13public 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
27public 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
2using System.Data;
3using System.Configuration;
4using System.Web;
5using System.Web.Security;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8using System.Web.UI.WebControls.WebParts;
9using System.Web.UI.HtmlControls;
10using System.Net.Mail;
11using System.Net;
12
13public 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
27public 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