China Telecom's IP address has been refreshed for a while, so I wrote a class to send emails from public IP addresses to my mailbox, Gmail, and 163 can all use javaspclient. QQ does not seem to work, I found it online, saying that QQ's SMTP cannot adapt to unzip pclient public class sendemailhelper {Private Static readonly ilog log = logmanager. getlogger (typeof (sendemailhelper); public static void sendemail () {try {// mailmessage mmsg = new mailmessage (); // mmsg. subject = "Public IP"; // mmsg. from = new mailaddress ("toddzhuang@gmail.com", "Todd Zhuang "); // Mmsg. to. add (New mailaddress ("54733648@qq.com"); // mmsg. isbodyhtml = true; // mmsg. bodyencoding = system. text. encoding. default; // mmsg. body = getwebcontent (@ "http://www.net.cn/static/customercare/yourIP.asp", LB); // smtpclient sclient = new smtpclient (); // sclient. host = "smtp.gmail.com"; // SMTP address of Google // sclient. port = 587; // Google's SMTP port // sclient. enablessl = true; // because Google uses SSL (Secure Socket Layer) encryption links Here, enablessl must be set to true. // Sclient. credentials = new networkcredential ("toddzhuang@gmail.com", "your password"); // sclient. send (mmsg); mailmessage mmsg = new mailmessage (); mmsg. subject = "Public IP"; mmsg. from = new mailaddress ("toddzhuang@163.com"); mmsg. to. add (New mailaddress ("54733648@qq.com"); mmsg. isbodyhtml = true; mmsg. bodyencoding = system. text. encoding. default; mmsg. body = getwebcontent (@ "http://www.net.cn/static/customercare/yourIP.asp"); smtpclient sclient = new smtpclient (); sclient. host = "smtp.163.com"; sclient. credentials = new networkcredential ("toddzhuang@163.com", "your password"); sclient. send (mmsg); log. info ("email sent successfully");} catch (exception e) {log. error (E. message) ;}} Private Static string getwebcontent (string URL) {string strresult = ""; try {httpwebrequest request = (httpwebrequest) webrequest. create (URL); // declare an httpwebrequest request. timeout = 30000; // set the connection timeout request. headers. set ("Pragma", "No-Cache"); httpwebresponse response = (httpwebresponse) request. getresponse (); stream streamreceive = response. getresponsestream (); encoding = encoding. getencoding ("gb2312"); streamreader = new streamreader (streamreceive, encoding); strresult = streamreader. readtoend (); log. info ("successful response to request webpage");} catch (exception e) {log. error (E. message) ;}return strresult ;}}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.