跳到主要內容

Asp.Net 利用gmail寄發信件

using System.Net.Mail;
 string id = hsEmailKey[txtEmail.Text].ToString();
            MailAddress from = new System.Net.Mail.MailAddress("XXX@gmail.com", "顯示名稱", System.Text.Encoding.UTF8);//自身gmail地址
            MailAddress to = new System.Net.Mail.MailAddress("對方mail地址", "二手書交流平台", System.Text.Encoding.UTF8);//對方mail地址
            MailMessage em = new MailMessage(from,to);
            em.SubjectEncoding = System.Text.Encoding.UTF8;//主旨編碼
            em.BodyEncoding = Encoding.UTF8;//內容編碼
            em.Subject = "來自二手書交流平台重要訊息";//主旨
            em.Body = String.Format("下面是您的帳號、密碼:\n註冊帳號:{0}\n註冊密碼:{1}\n請妥善保管以利快速登入", id, ((RegisterInformation)hsLogin[id]).getPass());//內文
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
            client.Credentials = new System.Net.NetworkCredential("XXX@gmail.com", "gmail密碼");//自己的
            client.Port = 587;//設定port
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true;
            client.Send(em);
            txtEmail.Text = "";
            Response.Redirect("redirect.htm");

留言

這個網誌中的熱門文章

java西元民國轉換_各種不同格式

C#資料庫操作(新增、修改、刪除、查詢)