码迷,mamicode.com
首页 > 其他好文 > 详细

QQ 发送邮件

时间:2018-11-03 12:28:16      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:als   set   sage   .net   extend   address   add   default   uap   

  之前也发布过一篇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 发送邮件

标签:als   set   sage   .net   extend   address   add   default   uap   

原文地址:https://www.cnblogs.com/freedom-ly/p/9900131.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!