ewefr

使用Gmail當作寄信主機

張貼者: Tony 2011年9月7日 星期三

using System.Net;

c#
---------------------------------------------------------------------------------------
string fromEmail = "service@gmail.com";
string fromName = "Manager";
MailAddress from = new MailAddress(fromEmail, fromName, Encoding.UTF8);
string toEmail = "tony1017888@gmail.com";
MailMessage mail = new MailMessage(from, new MailAddress(toEmail));
 string subject = "Test Subject";
 mail.Subject = subject;
 mail.SubjectEncoding = Encoding.UTF8;
 string body = "Test Body";
 mail.Body = body;
 mail.BodyEncoding = Encoding.UTF8;
 mail.IsBodyHtml = false;
 mail.Priority = MailPriority.High;
  // SMTP Setting
  SmtpClient client = new SmtpClient();
  client.Host = "smtp.gmail.com";
  client.Port = 587;
  client.Credentials = new NetworkCredential("username@gmail.com", "password");
  client.EnableSsl = true;
  // Send Mail
  client.Send(mail);
  // Sent Compeleted Eevet
   //client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);

0 意見

張貼留言

The Will Will Web

技術分享
MVP版主

重灌狂人

資訊分享

wowboxBlog

提供網頁設計相關資訊

KingKong Bruce記事

技術分享

C# Examples

csharp相關技術與範例

黑暗執行緒

技術分享
MVP版主

杨延成

技術分享
作者文章對於EF有詳細介紹

月光下的嘆息

工具分享
介紹許多好用的工具程式

Dot blogs

DotNet

格子樑/艾倫郭

技術分享
MVP版主