2011年7月21日 星期四

012-利用Gmail 寄信

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;

 

SmtpClient MySmtp = new SmtpClient("smtp.gmail.com",587);
MySmtp.UseDefaultCredentials = false;
MySmtp.Credentials = new NetworkCredential("帳號@gmail.com", "密碼");//設定帳號密碼
MySmtp.EnableSsl = true; //smtp 是否使用 SSL
MailMessage mms = new MailMessage();
mms.IsBodyHtml = false;//內容是不是HTML
mms.From = new MailAddress("帳號@gmail.com", "Gmail寄test", Encoding.UTF8);
mms.Sender = new MailAddress("帳號@gmail.com", "Gmail寄test", Encoding.UTF8);
mms.Subject = "C# Mail Test";//標題
mms.SubjectEncoding = Encoding.UTF8;
mms.To.Add(new MailAddress("andy@xx.COM.TW", "test", Encoding.UTF8));//收件者
mms.Body = "測試"; //內容
MySmtp.Send(mms);