using System.Net.Mail;
protected void Submit1_ServerClick(object sender, EventArgs e)
{
try
{
MailAddress From = new MailAddress(Request.Form["From"]);
MailAddress To = new MailAddress(Request.Form["To"]);
string Subject = "Subject Of the Mail";
string Body = "Body of the Mail";
// 設置郵件的發送及接收地址
MailMessage mailObj = new MailMessage(From, To,Subject,Body);
// Html格式的郵件
//mailObj.BodyFormat = MailFormat.Html;
// 設置為高級優先權
mailObj.Priority = MailPriority.High;
//1.1格式 // 為郵件添加附件 //構建一個認證實例,這裡是smtp服務器的地址 //將認證實例賦予mailClIEnt 這裡是登陸smtp的用戶名和密碼
//mailObj.FIElds.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //表示基本驗證
//mailObj.FIElds.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "fredlau21"); //在my_username_here處添加如163這樣的身份驗證的用戶名
//mailObj.FIElds.Add("or="#3c8266">http://schemas.microsoft.com/cdo/configuration/sendpassWord", "******"); // 在your_passWord_here處輸入密碼
// 注意:這裡我們創建了一個mailattachment對象添加一個附件到郵件中
//mailObj.Attachments.Add(new MailAttachment("c:\\test.doc"));
SmtpClient smtp = new SmtpClIEnt("smtp.163.com");
System.Net.NetworkCredential nc = new System.Net.NetworkCredential("[email protected]", "******");
smtp.Credentials = nc;
smtp.Send(mailObj);
Response.Write("發送成功!");
}
catch (Exception exp)
{
Response.Write(exp.Message);
}
}