public void SendAutomatedEmail(string yyyyMMdd)
{
string oSavePath = workDir + @"\your.file.name";
string ReceiveMail = "target@abc.com.tw";
string smtpHost = "ms.abc.com.tw";
string mailSubject = "IThelp";
string mailContext = stringHtml;
MailMessage MyMail = new System.Net.Mail.MailMessage();
MyMail.From = new System.Net.Mail.MailAddress("wkh@cht.com.tw");
MyMail.To.Add(ReceiveMail); //設定收件者Email
//MyMail.Bcc.Add("密件副本的收件者Mail"); //加入密件副本的Mail
MyMail.Subject = mailSubject + "(" + yyyyMMdd + ")";
MyMail.Body = mailContext ; //設定信件內容
MyMail.IsBodyHtml = true; //是否使用html格式
Attachment data = new Attachment(oSavePath, MediaTypeNames.Application.Octet);
MyMail.Attachments.Add(data);
System.Net.Mail.SmtpClient MySMTP = new System.Net.Mail.SmtpClient(smtpHost);
//MySMTP.Credentials = new System.Net.NetworkCredential("account", "PW");
try
{
MySMTP.Send(MyMail);
MyMail.Dispose(); //釋放資源
}
catch (Exception ex)
{
ex.ToString();
}
}
沒有留言:
張貼留言