예제 #1
0
파일: MailSend.cs 프로젝트: vbyte/fmq
        /// <summary>
        /// 发送HTML格式邮件(UTF8)
        /// </summary>
        public static SendStatus MailTo(SmtpConfig config, MailAddress AddrFrom, MailAddress AddrTo, MailAddressCollection cc, MailAddressCollection bCC,
            string Subject, string BodyContent, bool isHtml, List<Attachment> attC)
        {
            MailMessage msg = new MailMessage(AddrFrom == null ? new MailAddress(config.FromAddress) : AddrFrom, AddrTo);
            msg.Priority = MailPriority.High;

            #region 抄送
            if (cc != null && cc.Count > 0)
            {
                foreach (MailAddress cAddr in cc)
                {
                    msg.CC.Add(cAddr);
                }
            }
            #endregion

            #region 密送
            if (bCC != null && bCC.Count > 0)
            {
                foreach (MailAddress cAddr in bCC)
                {
                    msg.Bcc.Add(cAddr);
                }
            }
            #endregion

            #region 附件列表
            if (attC != null && attC.Count > 0)
            {
                foreach (Attachment item in attC)
                {
                    msg.Attachments.Add(item);
                }
            }
            #endregion

            msg.Subject = Subject;
            msg.SubjectEncoding = config.ContentEncoding;
            msg.BodyEncoding = config.ContentEncoding;
            msg.IsBodyHtml = isHtml;
            msg.Body = BodyContent;
            SmtpClient client = new SmtpClient(config.SmtpServer, config.Port);
            if (config.Credentials != null)
                client.Credentials = config.Credentials;
            client.EnableSsl = config.SSLConnect;

            SendStatus status = new SendStatus();
            try
            {
                client.Send(msg);
                status.Success = true;
            }
            catch (Exception exp)
            {
                status.Message = exp.Message;
            }
            return status;
        }
예제 #2
0
        /// <summary>
        /// 发送HTML格式邮件(UTF8)
        /// </summary>
        public static SendStatus MailTo(SmtpConfig config, MailAddress AddrFrom, MailAddress AddrTo, MailAddressCollection cc, MailAddressCollection bCC,
                                        string Subject, string BodyContent, bool isHtml, List <Attachment> attC)
        {
            MailMessage msg = new MailMessage(AddrFrom == null ? new MailAddress(config.FromAddress) : AddrFrom, AddrTo);

            msg.Priority = MailPriority.High;

            #region 抄送
            if (cc != null && cc.Count > 0)
            {
                foreach (MailAddress cAddr in cc)
                {
                    msg.CC.Add(cAddr);
                }
            }
            #endregion

            #region 密送
            if (bCC != null && bCC.Count > 0)
            {
                foreach (MailAddress cAddr in bCC)
                {
                    msg.Bcc.Add(cAddr);
                }
            }
            #endregion

            #region 附件列表
            if (attC != null && attC.Count > 0)
            {
                foreach (Attachment item in attC)
                {
                    msg.Attachments.Add(item);
                }
            }
            #endregion

            msg.Subject         = Subject;
            msg.SubjectEncoding = config.ContentEncoding;
            msg.BodyEncoding    = config.ContentEncoding;
            msg.IsBodyHtml      = isHtml;
            msg.Body            = BodyContent;
            SmtpClient client = new SmtpClient(config.SmtpServer, config.Port);
            if (config.Credentials != null)
            {
                client.Credentials = config.Credentials;
            }
            client.EnableSsl = config.SSLConnect;

            SendStatus status = new SendStatus();
            try
            {
                client.Send(msg);
                status.Success = true;
            }
            catch (Exception exp)
            {
                status.Message = exp.Message;
            }
            return(status);
        }