2017年5月16日 星期二

google mail 寄送設定

step1: 啟動兩階段驗證
step2: 取得 application 密碼
step3: 密碼欄位輸入 application 密碼

程式:
var fromAddress = new MailAddress("abcabc19871202@gmail.com", "From Name");
var toAddress = new MailAddress("xxx@gmail.com", "To Name");
const string fromPassword = "xxxxx"; //application 密碼
const string subject = "Subject";
const string body = "Body";

var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}

標籤: ,

0 個意見:

張貼留言

訂閱 張貼留言 [Atom]

<< 首頁