閑著蛋疼。計劃著改善公司的郵件服務(wù)。怎料公司網(wǎng)絡(luò)封閉的太厲害了。我只能在家里利用開放點的網(wǎng)絡(luò)來測試發(fā)送郵件;
利用qq郵箱發(fā)送到公司的企業(yè)郵箱上;
前提準備,登陸qq郵箱開啟stmp服務(wù)。不開啟的話沒法通過代碼登陸到你的郵箱;
查詢騰訊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) { //發(fā)件人地址 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測試通過!
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對服務(wù)器之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
原文鏈接:https://blog.csdn.net/chenqiangdage/article/details/41530941