Send Mail (public methods)

  #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  

 

Guess you like

Origin www.cnblogs.com/hugeboke/p/11574850.html