.net通過代碼發送郵件

來源:互聯網
上載者:User

標籤:

關鍵代碼:

需要引用命名空間:

using System.Net.Mail;
using System.Net;

 1    MailMessage mailObj = new MailMessage(); 2             3             mailObj.From = new MailAddress("[email protected]"); //發送人郵箱地址       4             mailObj.To.Add("[email protected]");   //收件者郵箱地址 5             mailObj.Subject = "賬戶啟用";    //主題 6             mailObj.Body = mailbody;    //本文, 7             mailObj.IsBodyHtml = true; //表示本文內容是HTML 8  9             SmtpClient smtp = new SmtpClient();10             smtp.Host = "smtp.sina.cn";         //smtp伺服器名稱11             smtp.UseDefaultCredentials = true;12             smtp.Credentials = new NetworkCredential("[email protected]", "pwd");  //發送人的登入名稱和密碼13             smtp.Send(mailObj);                

 

注意細節:

一、smtp

SMTP(Simple Mail Transfer Protocol)即簡易郵件傳輸通訊協定,它是一組由於源地址到目的地址傳送郵件的規則。

在使用時,要保證郵件裡該項服務已經開啟!新浪郵箱設定例如:

 

 

二、出現 “不允許使用郵箱名稱。 伺服器響應為:Envolope sender mismatch with login user..” 的錯誤

 

 

.net通過代碼發送郵件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.