class Program
{
static void Main(string[] args)
{
try
{
SmtpClient mySmtp = new SmtpClient("stmp host",smtp port);
//定義smtp的連接(smtp 網址,smtp port(預設25))
mySmtp.Credentials = new System.Net.NetworkCredential("account", "password");
//設定寄件者的認證(帳號,密碼)
MailMessage msgMail = new MailMessage();
//定義電子郵件
msgMail.From = new MailAddress("account@smtp host");
//寄件者
msgMail.To.Add("account@smtp host");
//收件者
msgMail.Subject = "mail subject";
//主旨
msgMail.SubjectEncoding = System.Text.Encoding.UTF8;
//主旨的編碼
msgMail.IsBodyHtml = true;
//設定郵件內容採用HTML格式
msgMail.Body = "mail content";
//設定郵件內容
msgMail.BodyEncoding = Encoding.UTF8;
//內容編碼
mySmtp.Send(msgMail);
//發送mail
Console.WriteLine("send success");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Console.ReadKey();
}
}
2012年8月20日 星期一
C# Send Mail (SmtpClient)
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言