引用System.Net.Mail名稱空間
public static void SendMail(string address, string displayName, string subject, string body)
{
MailAddress S_from = new MailAddress("User@abc.com", "寄件者"); //寄件者
MailAddress S_ReplyTo = new MailAddress("Replay@abc.com", "回覆者"); //信件回覆者
MailAddress S_to = new MailAddress(address, displayName); // 收件者
MailMessage Advmail = new MailMessage(); //建立MailMessage物件
Advmail.From = S_from;
Advmail.To.Add(S_to); // 加入收件者
Advmail.Subject = subject; // 設定信件主旨
Advmail.Priority = MailPriority.High; // Mail 優先權
Advmail.IsBodyHtml = true; // 設定信件內容是否採用html
Advmail.Body = body; // 加入信件內容
SmtpClient SmtpMail = new SmtpClient("smtp.abc.com", 25); //初始化SmtpClient,並加入郵件主機
SmtpMail.Credentials = new System.Net.NetworkCredential("account", "pwd"); // 驗證使用者的名稱與密碼
SmtpMail.Send(Advmail);
}
沒有留言:
張貼留言