閑著蛋疼。計劃著改善公司的郵件服務。怎料公司網絡封閉的太厲害了。我只能在家里利用開放點的網絡來測試發送郵件;
利用qq郵箱發送到公司的企業郵箱上;
前提準備,登陸qq郵箱開啟stmp服務。不開啟的話沒法通過代碼登陸到你的郵箱;

查詢騰訊qq郵箱的smtp主機地址為:smtp.qq.com 端口是587,或者465
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測試通過!
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對武林網的支持。如果你想了解更多相關內容請查看下面相關鏈接
新聞熱點
疑難解答