发送邮件

     using System.Net.Mail;//引入命名空间
        /// <summary>
        ///
        /// </summary>
        /// <param name="_MailEntity">邮件正文,标题..</param>
        /// <param name="isHTML">邮件正文是否是HTML格式</param>
        /// <param name="clientSmtp"></param>
        /// <param name="from">接收人</param>
        /// <returns></returns>
        public bool SendServiceMail(MailEntity _MailEntity, bool isHTML, string clientSmtp, string from)
        {
            try
            {
                SmtpClient client = new SmtpClient(clientSmtp);
                SmtpClient smtp = new SmtpClient();
                MailMessage mail = new MailMessage();
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;//将传输地址设置为Network(网络发送到smtp)
                MailMessage msg = new MailMessage(from, _MailEntity.MailTo);
                if (_MailEntity.MailCC != "")            
                    msg.CC.Add(_MailEntity.MailCC); //接收人邮箱          
                msg.SubjectEncoding = msg.BodyEncoding = Encoding.GetEncoding("gb2312");//设置编码
                msg.IsBodyHtml = isHTML;
                msg.Subject = _MailEntity.Subject;//邮件标题
                msg.Body = _MailEntity.Body;//邮件主体
                client.Send(msg);
                return true;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

posted @ 2017-10-13 10:35  cnblogs/yinbin  阅读(123)  评论(0编辑  收藏  举报