Exemplo n.º 1
0
        /// <summary>
        /// 定时发送===等待服务去跑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SingleTimerSend(Tnsmtp_EmailMap model)
        {
            BeginTransaction();


            #region 获取发件账户信息
            DataAccess.Tnsmtp_Account tnsmtp_Account = new DataAccess.Tnsmtp_Account();
            if (!tnsmtp_Account.SelectByPK(model.AccountId))
            {
                Rollback();
                Alert("获取发件账户失败");
                return(false);
            }
            #endregion

            #region 获取企业邮箱信息
            DataAccess.Tnsmtp_Mailtype tnsmtp_Mailtype = new DataAccess.Tnsmtp_Mailtype();
            if (!tnsmtp_Mailtype.SelectByPK(tnsmtp_Account.MailType))
            {
                Rollback();
                Alert("获取企业邮箱失败");
                return(false);
            }
            #endregion

            #region 判断收件人是否存在常用联系人,不存在则添加
            if (!AddContactTable(model))
            {
                Rollback();
                return(false);
            }

            #endregion

            #region 如果存在模板标签则替换模板标签
            string      content = string.Empty;
            ReplaceMark replace = new ReplaceMark();
            if (!replace.Replace(model, model.Userid, out content))
            {
                Rollback();
                Alert("替换模板标签失败!");
                return(false);
            }

            #endregion

            #region 添加数据库 邮件表

            model.FlagStatus = (int)Entites.EmailFlagStatus.定时邮件;;

            if (!SingleAddEmailTable(model))
            {
                Rollback();
                Alert("添加邮件失败");
                return(false);
            }

            #endregion

            #region 如果有附件,则添加附件到数据库
            Dictionary <string, string> filelist  = new Dictionary <string, string>();
            AttchmentFacade             attchment = new AttchmentFacade();
            if (!attchment.AddAtthachmentTable(model, tnsmtp_Account, out filelist))
            {
                Rollback();
                Alert("添加附件失败!");
                return(false);
            }

            #endregion


            Commit();
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 向用户发送普通邮件====即时发送
        /// </summary>
        public bool SingleSend(Tnsmtp_EmailMap model)
        {
            BeginTransaction();

            #region 前期准备工作

            #region 获取发件账户信息
            DataAccess.Tnsmtp_Account tnsmtp_Account = new DataAccess.Tnsmtp_Account();
            if (!tnsmtp_Account.SelectByPK(model.AccountId))
            {
                Rollback();
                Alert("获取发件账户失败");
                return(false);
            }
            #endregion

            #region 获取企业邮箱信息
            DataAccess.Tnsmtp_Mailtype tnsmtp_Mailtype = new DataAccess.Tnsmtp_Mailtype();
            if (!tnsmtp_Mailtype.SelectByPK(tnsmtp_Account.MailType))
            {
                Rollback();
                Alert("获取企业邮箱失败");
                return(false);
            }
            #endregion

            #region 判断收件人是否存在常用联系人,不存在则添加
            if (!AddContactTable(model))
            {
                Rollback();
                return(false);
            }

            #endregion

            #region 如果存在模板标签则替换模板标签
            string      content = string.Empty;
            ReplaceMark replace = new ReplaceMark();
            if (!replace.Replace(model, model.Userid, out content))
            {
                Rollback();
                Alert("替换模板标签失败!");
                return(false);
            }

            #endregion

            #region 添加数据库 邮件表

            model.Senddate = DateTime.Now;
            if (!SingleAddEmailTable(model))
            {
                Rollback();
                Alert("添加邮件失败");
                return(false);
            }

            #endregion

            #region 如果有附件,则添加附件到数据库
            Dictionary <string, string> filelist  = new Dictionary <string, string>();
            AttchmentFacade             attchment = new AttchmentFacade();
            if (!attchment.AddAtthachmentTable(model, tnsmtp_Account, out filelist))
            {
                Rollback();
                Alert("添加附件失败!");
                return(false);
            }

            #endregion

            #region 判断是否有抄送或者密送


            List <string> Bcc = new List <string>();
            List <string> Wcc = new List <string>();


            if (!Entites.Tool.SplitContact.GetCCArray(model.Bcc, out Bcc))
            {
                Alert("密送联系人地址有误");
                Rollback();
                return(false);
            }


            if (!Entites.Tool.SplitContact.GetCCArray(model.Wcc, out Wcc))
            {
                Alert("抄送联系人地址有误");
                Rollback();
                return(false);
            }


            #endregion


            #endregion

            try
            {
                #region 调用SMTP 发送邮件
                SmtpMail smtp = new SmtpMail();
                smtp.AddRecipient(model.Inmail);

                smtp.MailDomain     = tnsmtp_Mailtype.SmtpUrl;
                smtp.Html           = true;
                smtp.From           = model.Tomail;
                smtp.FromName       = model.Tomail;
                smtp.RecipientName  = model.Inmail;
                smtp.MailDomainPort = tnsmtp_Mailtype.SmtpSsl;
                smtp.Subject        = model.Subject;
                smtp.Body           = model.Content;
                smtp.AttachmentFile = filelist;

                smtp.MailServerUserName = tnsmtp_Account.Account;
                smtp.MailServerPassWord = tnsmtp_Account.Password;

                smtp.RecipientBCC1 = Bcc;
                smtp.RecipientWCC1 = Wcc;



                if (!smtp.Send())
                {
                    Rollback();
                    Alert(smtp.PromptInfo.Message);
                    return(false);
                }

                #endregion
            }
            catch (Exception e)
            {
                Log.Info("发送异常!" + e);
                Rollback();
                Alert(e.Message);
                return(false);
            }

            Commit();
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 群发邮件====让服务即时去跑
        /// </summary>
        /// <param name="model"></param>
        /// <param name="Gid"></param>
        /// <returns></returns>
        public bool GroupSend(Tnsmtp_EmailMap model, int Gid)
        {
            BeginTransaction();

            #region 获取发件账户信息
            DataAccess.Tnsmtp_Account tnsmtp_Account = new DataAccess.Tnsmtp_Account();
            if (!tnsmtp_Account.SelectByPK(model.AccountId))
            {
                Rollback();
                Alert("获取发件账户失败");
                return(false);
            }
            #endregion

            #region 获取企业邮箱信息
            DataAccess.Tnsmtp_Mailtype tnsmtp_Mailtype = new DataAccess.Tnsmtp_Mailtype();
            if (!tnsmtp_Mailtype.SelectByPK(tnsmtp_Account.MailType))
            {
                Rollback();
                Alert("获取企业邮箱失败");
                return(false);
            }
            #endregion

            #region 如果存在模板标签则替换模板标签
            string      content = string.Empty;
            ReplaceMark replace = new ReplaceMark();
            if (!replace.Replace(model, model.Userid, out content))
            {
                Rollback();
                Alert("替换模板标签失败!");
                return(false);
            }

            #endregion


            DataAccess.Tnsmtp_ContactCollection tnsmtp_ContactCollection = new Tnsmtp_ContactCollection();

            if (!tnsmtp_ContactCollection.ListByUserid(model.Userid, string.Empty, Gid))
            {
                Rollback();
                Alert("查找分组联系人失败");
                return(false);
            }

            foreach (DataRow dr in tnsmtp_ContactCollection.DataTable.Rows)
            {
                model.FlagStatus = (int)Entites.EmailFlagStatus.群发;
                model.Inmail     = dr[Tnsmtp_Contact._EMAIL].ToString();

                if (!GroupAddEmailTable(model))
                {
                    Rollback();
                    Alert("添加邮件失败");
                    return(false);
                }


                Dictionary <string, string> filelist  = new Dictionary <string, string>();
                AttchmentFacade             attchment = new AttchmentFacade();
                if (!attchment.AddAtthachmentTable(model, tnsmtp_Account, out filelist))
                {
                    Rollback();
                    Alert("添加附件失败!");
                    return(false);
                }
            }



            Commit();
            return(true);
        }