標籤:red odi string 郵件服務 add smtp blog gpo user
public static bool SendMailUse()
{
string host = "smtp.163.com";// 郵件伺服器smtp.163.com表示網易郵箱伺服器
string userName = "[email protected]";// 發送端帳號
string password = "a96606";// 發送端密碼(這個用戶端重設後的密碼)
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;//指定電子郵件發送方式
client.Host = host;//郵件伺服器
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(userName, password);//使用者名稱、密碼
string strfrom = userName;
string strto = "[email protected]";
//string strcc = "[email protected]";//抄送
string subject = "訂單標題";//郵件的主題
string body = "訂單標題";//發送的郵件內文
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress(strfrom, "訂單");
msg.To.Add(strto);
//msg.CC.Add(strcc);
msg.Subject = subject;//郵件標題
msg.Body = body;//郵件內容
msg.BodyEncoding = System.Text.Encoding.UTF8;//郵件內容編碼
msg.IsBodyHtml = true;//是否是HTML郵件
msg.Priority = MailPriority.High;//郵件優先順序
try
{
client.Send(msg);
return true;
}
catch (System.Net.Mail.SmtpException ex)
{
return false;
}
}
C#SMTP發郵件