今天搞一個發郵件的小功能,一切參數設置好,就是服務器沒響應。
一開始懷疑是郵件服務器設置不對,郵件服務器和outlook中找到的是一致的。
懷疑端口號25不對。大部分資料都說是25呀。
。。。
後來找到這個網頁,說
Usually an outgoing server employs port 25: it's the default SMTP port. However, some IPs deny its use because of the massive spam and malware traffic by which is affected. This issue is raised in particular when you need to switch to another ISP – for instance, when you're travelling and connecting to a new provider. In this case you can try to use port 587 or port 465 to avoid the block.
More in detail: port 587 is supported by almost every outgoing SMTP server and it's useful for unencrypted or TLS connections; while port 465 is the right choice if you need to connect via SSL.
摘自:http://www.serversmtp.com/en/port-for-smtp
即:25是默認端口,可能因為spam等原因用不了,這時可以考慮587.一般對於非加密的請求587都能用。
修改端口號為587後,果然OK。
附:
C#開發郵件客戶端使用SmtpClient。
使用原理:需要設置郵件服務器地址,及端口號。