asp.net——QQ郵箱發送郵件

來源:互聯網
上載者:User

標籤:技術   ges   password   bsp   並發   asp   添加   images   message   

1.擷取QQ郵箱的授權碼

  開啟QQ郵箱 - 設定 - 賬戶 - 開啟POP3/SMTP服務 -> 根據操作擷取授權碼

 

2.設定並發送郵件——方法1

(兩種配置方式)

  -1:配置Web.config,在<configuration>標籤中添加以下代碼

    (aaaaaaaaaa:表示你發信人的郵箱號.

      bbbbbbbbbb:表示你前面擷取的授權碼.

      連接埠號碼port:我測試25能發,而465不能發(不知道為什麼).)

<system.net>  <mailSettings>    <smtp deliveryMethod="Network" from="nekorz <[email protected]>">      <network host="smtp.qq.com" userName="[email protected]" password="bbbbbbbbbb" port="25" />    </smtp>  </mailSettings></system.net>

 

  -2:添加發送郵件代碼

    (暱稱:可有可無)

        MailMessage myMessage = new MailMessage();        myMessage.Subject = "Test Message";        myMessage.Body = "這是一封測試郵件.";        myMessage.To.Add(new MailAddress("[email protected]", "暱稱"));        SmtpClient mySmtpClient = new SmtpClient();        mySmtpClient.EnableSsl = true;        try        {            mySmtpClient.Send(myMessage);        }        catch (SmtpException ex)        {        }

 

3.設定並發送郵件——方法2

  (僅是把在Web.config中的配置,轉移到了代碼中)

        MailMessage myMessage = new MailMessage();        myMessage.Subject = "Test Message";        myMessage.Body = "這是一封測試郵件";        myMessage.From = new MailAddress("[email protected]", "暱稱");        myMessage.To.Add(new MailAddress("[email protected]", "暱稱"));        SmtpClient mySmtpClient = new SmtpClient();        mySmtpClient.Host = "smtp.qq.com";        mySmtpClient.Port = 25;        mySmtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "bbbbbbbbbb");        mySmtpClient.EnableSsl = true;        try        {            mySmtpClient.Send(myMessage);        }        catch (SmtpException ex)        {        }

 

asp.net——QQ郵箱發送郵件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.