要匯入 System.Net 和 System.Net.Mail 兩套件。
string fromEmail = "DavidKuo'sMail@gmail.com"; // 寄信人
string fromName = "DavidKuo"; // 寄信人姓名
MailAddress from = new MailAddress(fromEmail, fromName, Encoding.UTF8);
string toEmail = "A'sMail@gmail.com"; // 收信人
MailMessage mail = new MailMessage(from, new MailAddress(toEmail));
string subject = "subject";
mail.Subject = subject;
mail.SubjectEncoding = Encoding.UTF8;
string body = "body";
mail.Body = body;
mail.BodyEncoding = Encoding.UTF8;
mail.IsBodyHtml = false; // 是否為 Html 格式
mail.Priority = MailPriority.High; // 信件優先權
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 587;
client.Credentials = new NetworkCredential("DavidKuo'sMail@gmail.com", "DavidKuo'sMailPassword");
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(mail); // 寄信
參考網址:http://www.dotblogs.com.tw/chhuang/archive/2008/03/18/1815.aspx
回目錄
回首頁
沒有留言 :
張貼留言