QQ 傳送郵件
阿新 • • 發佈:2018-11-03
之前也釋出過一篇QQ發郵件的,後來那種方法在阿里雲伺服器中報錯了,查了好久才發現,是阿里雲的伺服器把 25 埠 給封殺了。現在重新做了個功能。
public static string UserName = ""; public static string UserPass = ""; /// <summary> /// 向用戶傳送郵件 /// </summary> /// <param name="ReceiveUser">接收郵件的使用者</param> ///<param name="MailTitle">傳送標題</param> /// <param name="valiCode">傳送的驗證碼</param> /// <returns>bool</returns> public static bool sendMail(string ReceiveUser, string MailTitle, string valiCode) { //儲存驗證碼 var authCode = valiCode; UAP.Session.Set("authCode", valiCode); MailAddress toMail = new MailAddress(ReceiveUser); MailAddress fromMail = new MailAddress(UserName, "51流量神器"); MailMessage mail = new MailMessage(fromMail, toMail); mail.Subject = MailTitle; mail.IsBodyHtml = true; mail.Body= "【" + MailTitle + "】您好,您的驗證碼是:" + valiCode + " ."; ; SmtpClient client = new SmtpClient(); client.Host = "smtp.exmail.qq.com"; client.Port = 587; //25 埠已被阿里雲全面封殺 client.EnableSsl = true; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(UserName, UserPass); client.DeliveryMethod = SmtpDeliveryMethod.Network; try { client.Send(mail); return true; } catch(Exception ex) { Extend.WriteTextLog("SendEmail", ex.Message, DateTime.Now, "Email_Error"); throw; } }