代码
转自:http://www.cnblogs.com/phcis/archive/2010/03/02/1676577.html
string
v_smtpAddress
=
"
smtp.xxx.com
"
;
//
smtp地址,如smtp.163.com
string v_sendMailUserName = " userName " ; // 发送邮件使用的用户名
string v_sendMailPassword = " userPwd " ; // 发送邮件使用的密码
string v_sendMailAddress = " phcis@163.com " ; // 发送邮件的mail地址
string v_receiveMailAddress = " phcis@163.com " ; // 接收邮件的mail地址
string v_mailSubject = " 邮件主题 " ; // 邮件主题
SmtpClient smtp = new SmtpClient(v_smtpAddress);
smtp.Credentials = new System.Net.NetworkCredential(v_sendMailUserName, v_sendMailPassword);
MailMessage mes = new MailMessage();
mes.From = new MailAddress(v_sendMailAddress);
mes.To.Add(v_receiveMailAddress);
mes.Subject = v_mailSubject;
mes.Body = TextArea1.Value;
mes.IsBodyHtml = true ; // 使用是否html格式
// 增加附件
System.Net.Mail.Attachment mailAttach_1 = new Attachment( @" d:\b.txt " );
mes.Attachments.Add(mailAttach_1);
smtp.Send(mes);
mailAttach_1.Dispose(); // 释放由附件占用的资源
string v_sendMailUserName = " userName " ; // 发送邮件使用的用户名
string v_sendMailPassword = " userPwd " ; // 发送邮件使用的密码
string v_sendMailAddress = " phcis@163.com " ; // 发送邮件的mail地址
string v_receiveMailAddress = " phcis@163.com " ; // 接收邮件的mail地址
string v_mailSubject = " 邮件主题 " ; // 邮件主题
SmtpClient smtp = new SmtpClient(v_smtpAddress);
smtp.Credentials = new System.Net.NetworkCredential(v_sendMailUserName, v_sendMailPassword);
MailMessage mes = new MailMessage();
mes.From = new MailAddress(v_sendMailAddress);
mes.To.Add(v_receiveMailAddress);
mes.Subject = v_mailSubject;
mes.Body = TextArea1.Value;
mes.IsBodyHtml = true ; // 使用是否html格式
// 增加附件
System.Net.Mail.Attachment mailAttach_1 = new Attachment( @" d:\b.txt " );
mes.Attachments.Add(mailAttach_1);
smtp.Send(mes);
mailAttach_1.Dispose(); // 释放由附件占用的资源