QQ 发送邮件
Posted freedom-ly
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了QQ 发送邮件相关的知识,希望对你有一定的参考价值。
之前也发布过一篇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; } }
以上是关于QQ 发送邮件的主要内容,如果未能解决你的问题,请参考以下文章