using System.Net.Mail;
public void SendMail()
{
  //設定smtp主機
  SmtpClient mySmtp = new SmtpClient("smtp.hinet.net");
  //設定smtp帳密
  mySmtp.Credentials = new System.Net.NetworkCredential("user", "password");
  //信件內容
  string pcontect = "string or html";
  //設定mail內容
  MailMessage msgMail = new MailMessage();
  //寄件者
  msgMail.From = new MailAddress("sys@hinet.net");
  //收件者
  msgMail.To.Add("user@hinet.net");
  //主旨
  msgMail.Subject = "信件主旨";
  //信件內容(含HTML時)
  AlternateView alt = AlternateView.CreateAlternateViewFromString(pcontect, null, "text/html");
  msgMail.AlternateViews.Add(alt);
  //寄mail
  mySmtp.Send(msgMail);
}

arrow
arrow
    全站熱搜

    Joe Joe 發表在 痞客邦 留言(0) 人氣()