using System.Web.Mail;
------------------------------------------------------------
MailMessage mailMsg = new MailMessage();
//设置正文格式
mailMsg.BodyFormat = MailFormat.Html;
//设置收件人的邮件地址
mailMsg.To = "00@qq.com";
//设置发送者的邮件地址
mailMsg.From = "我们<00@qq.com>";
//设置邮件主题
mailMsg.Subject = "【测试标题】";
//设置邮件内容
mailMsg.Body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\"http://www.w3.org/TR/html4/loose.dtd\"><html>正文测试!!!</html>";
//设置支持服务器验证
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置用户名
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "00");
//设置用户密码
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "00");
MailAttachment file = new MailAttachment(@"C:\VITAS.mp3");
MailAttachment file2 = new MailAttachment(@"C:\新建 文本文档.txt");
mailMsg.Attachments.Add(file);
mailMsg.Attachments.Add(file2);
try
{
//设置发送邮件服务器
SmtpMail.SmtpServer = "smtp.qq.com";
//发送邮件
SmtpMail.Send(mailMsg);
}
catch (Exception err)
{
Response.Write("发送失败" + err.Message.ToString());
}