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());
}