代码:
1
MailMessage objmail=new MailMessage ();
2
MailAttachment objmailattach=new MailAttachment (accessorymail.Value .ToString ());
3
//附件
4
objmail.From =sourcemail.Value .ToString ();
5
objmail.To =targetmail.Value .ToString ();
6
objmail.Subject =subjectmail.Value .ToString ();
7
objmail.Body =contentmail.Value .ToString ();
8
objmail.Attachments .Add (objmailattach);
9
10
objmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
11
objmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "userid");//这里填写你邮箱的用户名
12
objmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "pwd");//你邮箱的密码
13
SmtpMail.SmtpServer = "smtp.163.com";
14
//如是局域网内发邮件,则把此设为内部邮件服务器的IP
15
16
try
17
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2.采用JMail来发送邮件和接受邮件
下载JMAIL,并安装:JMail
重新编绎jmail.dll,见http://tintown.cnblogs.com/archive/2006/01/26/323575.html
发送邮件代码:
1
Message jmail=new Message ();
2
jmail.AddRecipient ("接受邮箱",null,null);
3
jmail.From ="发送邮箱";
4
jmail.MailServerUserName ="发送邮箱用户名";
5
jmail.MailServerPassWord ="发送邮箱密码";
6
jmail.Subject ="test";
7
jmail.Body ="test jmail"+System.DateTime .Now.ToString (); jmail.Send ("smtp.163.com",false);
8
jmail.Close ();
9
this.Response .Write ("ok");
接受邮件代码:2
3
4
5
6
7
8
9
1
POP3 pop=new POP3Class ();
2
pop.Connect ("用户名","密码","pop3.163.com",110);
3
StringWriter sw=new StringWriter ();
4
HtmlTextWriter ht=new HtmlTextWriter (sw);
5
ht.RenderBeginTag ("table");
6
for(int i=1;i<pop.Messages .Count;i++)
7
.Response .Write (sw.ToString ());
2
3
4
5
6
7