asp.net System.Net.Mail 發送郵件

來源:互聯網
上載者:User

舉例: 複製代碼 代碼如下:163.com的郵箱在早期申請的是支援的,後面申請的都是不支援。
21cn.com似乎現在已經放棄了smtp支援,可能只有繳費使用者才可以。
qq.com的郵箱需要在使用者帳戶裡面設定。

我拿了個sina.com的郵箱進行測試,也需要在後台裡面的

才可以發送。詳細代碼如下:複製代碼 代碼如下:MailAddress from = new MailAddress("sosuo8@sina.com");
MailAddress to = new MailAddress("ahuinan@21cn.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "阿會楠的來信";
message.Body = "你好!測試而已";
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = 25;
client.Host = "smtp.sina.com";
client.Credentials = new System.Net.NetworkCredential("sosuo8@sina.com", "123");
Response.Write("發送一份郵件到" + to.User + "," + to.Host +"," + client.Host);
client.Send(message);

別忘了引入命名空間:複製代碼 代碼如下:using System.Net;
using System.Net.Mail ;

相關文章

聯繫我們

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