首页 > 其他 > 详细

发送邮件(公共方法)

时间:2019-09-23 21:29:54      阅读:115      评论:0      收藏:0      [点我收藏+]
  #region 发送邮件

        public bool Send(string email, string title, string body)
        {
            string message="发送成功";

            return Send(email, title, body, out message);
        }

        public bool Send(string email, string title, string body,out string message)
        {
            message = "发送成功";

            bool returnValue = true;
            try
            {
                System.Web.Mail.MailMessage myEmail = new System.Web.Mail.MailMessage();
                myEmail.From = FromEmail;
                myEmail.To = email;
                myEmail.Subject = title;
                myEmail.Body = body;

                myEmail.BodyFormat = System.Web.Mail.MailFormat.Html; //邮件形式,.Text、.Html 

                // 通过SMTP服务器验证


                if (!string.IsNullOrEmpty(UserName))
                {
                    myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
                    myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", UserName); //set your username here
                    myEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password); //set your password here
                }


                System.Web.Mail.SmtpMail.SmtpServer = SmtpServer;
                //System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();

                System.Web.Mail.SmtpMail.Send(myEmail);

            }
            catch (Exception e)
            {
                message = e.ToString();
                returnValue = false;
                logger.Error(e.ToString());
            }

            return returnValue;
        }
       #endregion  

 

发送邮件(公共方法)

原文:https://www.cnblogs.com/hugeboke/p/11574850.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!