1
string
v_smtpAddress
=
"
smtp.xxx.com
"
;
//
smtp地址,如smtp.163.com
2 string v_sendMailUserName = " userName " ; // 发送邮件使用的用户名
3 string v_sendMailPassword = " userPwd " ; // 发送邮件使用的密码
4 string v_sendMailAddress = " phcis@163.com " ; // 发送邮件的mail地址
5 string v_receiveMailAddress = " phcis@163.com " ; // 接收邮件的mail地址
6 string v_mailSubject = " 邮件主题 " ; // 邮件主题
7
8
9 SmtpClient smtp = new SmtpClient(v_smtpAddress);
10 smtp.Credentials = new System.Net.NetworkCredential(v_sendMailUserName, v_sendMailPassword);
11 MailMessage mes = new MailMessage();
12
13 mes.From = new MailAddress(v_sendMailAddress);
14 mes.To.Add(v_receiveMailAddress);
15
16 mes.Subject = v_mailSubject;
17 mes.Body = TextArea1.Value;
18 mes.IsBodyHtml = true ; // 使用是否html格式
19
20 // 增加附件
21 System.Net.Mail.Attachment mailAttach_1 = new Attachment( @" d:\b.txt " );
22 mes.Attachments.Add(mailAttach_1);
23
24 smtp.Send(mes);
25 mailAttach_1.Dispose(); // 释放由附件占用的资源
2 string v_sendMailUserName = " userName " ; // 发送邮件使用的用户名
3 string v_sendMailPassword = " userPwd " ; // 发送邮件使用的密码
4 string v_sendMailAddress = " phcis@163.com " ; // 发送邮件的mail地址
5 string v_receiveMailAddress = " phcis@163.com " ; // 接收邮件的mail地址
6 string v_mailSubject = " 邮件主题 " ; // 邮件主题
7
8
9 SmtpClient smtp = new SmtpClient(v_smtpAddress);
10 smtp.Credentials = new System.Net.NetworkCredential(v_sendMailUserName, v_sendMailPassword);
11 MailMessage mes = new MailMessage();
12
13 mes.From = new MailAddress(v_sendMailAddress);
14 mes.To.Add(v_receiveMailAddress);
15
16 mes.Subject = v_mailSubject;
17 mes.Body = TextArea1.Value;
18 mes.IsBodyHtml = true ; // 使用是否html格式
19
20 // 增加附件
21 System.Net.Mail.Attachment mailAttach_1 = new Attachment( @" d:\b.txt " );
22 mes.Attachments.Add(mailAttach_1);
23
24 smtp.Send(mes);
25 mailAttach_1.Dispose(); // 释放由附件占用的资源