閑著蛋疼。計劃著改善公司的郵件服務。怎料公司網絡封閉的太厲害了。我只能在家里利用開放點的網絡來測試發送郵件;
利用qq郵箱發送到公司的企業郵箱上;
前提準備,登陸qq郵箱開啟stmp服務。不開啟的話沒法通過代碼登陸到你的郵箱;
查詢騰訊qq郵箱的smtp主機地址為:smtp.qq.com 端口是587,或者465
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
using system; using system.collections.generic; using system.linq; using system.text; using system.net.mail; namespace mail { class program { static void main( string [] args) { //發件人地址 mailaddress from = new mailaddress( "*********@qq.com" ); mailmessage message = new mailmessage(); message.body = "this is a test" ; message.isbodyhtml = true ; message.bodyencoding = system.text.encoding.utf8; //收件人地址 message.to.add( "********bizip.com" ); message.subject = "hello !" ; message.subjectencoding = system.text.encoding.utf8; message.from = from; smtpclient client = new smtpclient(); client.enablessl = true ; client.host = "smtp.qq.com" ; client.port = 587; //郵箱賬戶和密碼 client.credentials = new system.net.networkcredential( "mailacount" , "password" ); try { client.send(message); } catch (exception ex) { string mssage = ex.tostring(); } } } } |
很簡單啊
vs2010測試通過!
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對服務器之家的支持。如果你想了解更多相關內容請查看下面相關鏈接
原文鏈接:https://blog.csdn.net/chenqiangdage/article/details/41530941