close

記錄發送Mail的功能:

MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("寄件者");
Msg.To.Add("收件者");
Msg.To.Add("收件者");

Msg.CC.Add("副本收件者");

Msg.Bcc.Add("密件副本");

Msg.Subject = "Test Mail";//標題
Msg.Body = "content test!!";//內文
Msg.SubjectEncoding = Encoding.UTF8;
Msg.BodyEncoding = Encoding.UTF8;//編碼
Msg.IsBodyHtml = true;//是否以html顯示

string filePath = @"D:\test.pdf"; //要附加的檔案
Attachment attachment1 = new Attachment(filePath);
attachment1.Name = System.IO.Path.GetFileName(filePath);
attachment1.NameEncoding = Encoding.GetEncoding("utf-8");
attachment1.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;//編碼
attachment1.ContentDisposition.Inline = true;
attachment1.ContentDisposition.DispositionType = System.Net.Mime.DispositionTypeNames.Inline;
Msg.Attachments.Add(attachment1);

SmtpClient smtp = new SmtpClient("SMTP位置");
smtp.EnableSsl = true;//是否開啟SSL連線
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential("帳號","密碼");
SmtpClient smtp = new SmtpClient(WebConfigurationManager.ConnectionStrings["webconfig紀錄之連線資訊"].ConnectionString);

try
{
      smtp.Send(Msg);
      attachment1.Dispose();
      Msg.Dispose();

}
catch (Exception ex)
{
      Response.Write(ex.ToString());
}
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 芭樂養樂多 的頭像
    芭樂養樂多

    隨手筆記

    芭樂養樂多 發表在 痞客邦 留言(0) 人氣()