using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Net; using System.Net.Mail; namespace MVC4_discuzV2.Controllers { public class RegisterController : Controller { // // GET: /Register/ public ActionResult Index() { SendSMTPEMail("smtp.163.com", xxoo@163.com", "xxooxx", "936727003@qq.com", "w!!!", "e@@@"); return View(); } public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody) { System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass); client.DeliveryMethod = SmtpDeliveryMethod.Network; System.Net.Mail.MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody); message.BodyEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; message.Headers.Add("X-Priority", "3"); message.Headers.Add("X-MSMail-Priority", "Normal"); message.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869"); message.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869"); message.Headers.Add("ReturnReceipt", "1"); client.Send(message); } //第一个参数如果是163邮箱就写smtp.163.com //第二个参数发件人的帐号 //第三个参数发件人密码 //第四个参数收件人帐号 //第五个参数主题 //第六个参数内容. } }
之间试过 smtp.qq.com 的 ,没成功 ,貌似,现在qq 不允许这么干了,毕竟耗得是别人的邮件服务器。还是 163
大方,如果哪天你不能发了,说明 163 变小气了,代码本人2014-03-07测试时没有问题的!message.Headers.Add
后面的5行,加上就不再是垃圾邮件了,据说这是 仿造 outlook 的邮件标题 。