Beispiel #1
0
        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindDataToPage()
        {
            //发件人邮箱
            txtSenderEmail.Text = Settings["PowerForms_SenderEmail"] != null && !string.IsNullOrEmpty(Settings["PowerForms_SenderEmail"].ToString()) ? Convert.ToString(Settings["PowerForms_SenderEmail"]) : Host.HostEmail;

            #region "邮件设置"
            txtAdminEmail.Text         = Settings["PowerForms_AdminEmail"] != null && !string.IsNullOrEmpty(Settings["PowerForms_AdminEmail"].ToString()) ? Convert.ToString(Settings["PowerForms_AdminEmail"]) : Host.HostEmail;
            cbSendToAdmin.Checked      = Settings["PowerForms_SendToAdmin"] != null && !string.IsNullOrEmpty(Settings["PowerForms_SendToAdmin"].ToString()) ? Convert.ToBoolean(Settings["PowerForms_SendToAdmin"]) : true;
            cbSendToSubmitUser.Checked = Settings["PowerForms_SendToSubmitUser"] != null && !string.IsNullOrEmpty(Settings["PowerForms_SendToSubmitUser"].ToString()) ? Convert.ToBoolean(Settings["PowerForms_SendToSubmitUser"]) : true;
            //cbReplaceSender.Checked = Settings["PowerForms_ReplaceSender"] != null && !string.IsNullOrEmpty(Settings["PowerForms_ReplaceSender"].ToString()) ? Convert.ToBoolean(Settings["PowerForms_ReplaceSender"]) : false;
            cbReplyTo.Checked = Settings["PowerForms_ReplyTo"] != null?Convert.ToBoolean(Settings["PowerForms_ReplyTo"]) : true;

            WebHelper.BindList <DNNGo_PowerForms_Field>(ddlSubmitUserEmail, DNNGo_PowerForms_Field.FindAllByView(ModuleId, EnumVerification.email), DNNGo_PowerForms_Field._.Alias, DNNGo_PowerForms_Field._.Name);
            WebHelper.SelectedListByValue(ddlSubmitUserEmail, Settings["PowerForms_SubmitUserEmail"] != null && !string.IsNullOrEmpty(Settings["PowerForms_SubmitUserEmail"].ToString()) ? Convert.ToString(Settings["PowerForms_SubmitUserEmail"]) : "Email");


            DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();
            WebHelper.BindList(cblAdminEmailRoles, rc.GetPortalRoles(PortalId), "RoleName", "RoleName");
            WebHelper.SelectedListMultiByValue(cblAdminEmailRoles, Settings["PowerForms_AdminEmailRoles"] != null ? Convert.ToString(Settings["PowerForms_AdminEmailRoles"]) : "");


            //需要读取模版的设置
            DNNGo_PowerForms_Template Template = DNNGo_PowerForms_Template.FindByModuleId(ModuleId);

            txtSendAdminTitle.Text        = !String.IsNullOrEmpty(Template.ReceiversSubject) ? Template.ReceiversSubject : Localization.GetString("PowerForms_ReceiversSubject", this.LocalResourceFile);
            txtSendAdminContent.Text      = !String.IsNullOrEmpty(Template.ReceiversTemplate) ? Server.HtmlDecode(Template.ReceiversTemplate) : Localization.GetString("PowerForms_ReceiversTemplate", this.LocalResourceFile);
            txtSendSubmitUserTitle.Text   = !String.IsNullOrEmpty(Template.ReplySubject) ? Template.ReplySubject : Localization.GetString("PowerForms_ReplySubject", this.LocalResourceFile);
            txtSendSubmitUserContent.Text = !String.IsNullOrEmpty(Template.ReplyTemplate) ? Server.HtmlDecode(Template.ReplyTemplate) : Localization.GetString("PowerForms_ReplyTemplate", this.LocalResourceFile);
            #endregion

            #region "定时邮件设置"
            DNNGo_PowerForms_Scheduler SchedulerItem = DNNGo_PowerForms_Scheduler.FindSettings(this);
            txtScheduleSenderEmail.Text = !String.IsNullOrEmpty(SchedulerItem.SenderEmail) ? SchedulerItem.SenderEmail: Host.HostEmail;
            txtExcelName.Text           = !String.IsNullOrEmpty(SchedulerItem.ExcelName) ? SchedulerItem.ExcelName : "Bulk_{yyyy}_{mm}_{dd}_{time}_{ModuleID}";
            cbScheduleEnable.Checked    = SchedulerItem.Enable != 0;

            #endregion
        }
Beispiel #2
0
        /// <summary>
        /// 提交成功发送邮件
        /// 1.构造管理员邮件并发送
        /// 2.构造提交者的邮件并发送
        /// </summary>
        /// <param name="SubmitContent"></param>
        public void SendMail(DNNGo_PowerForms_Content SubmitContent, List <DNNGo_PowerForms_ContentItem> ContentList, List <DNNGo_PowerForms_Field> FieldList)
        {
            DNNGo_PowerForms_Template Template = Settings_EmailTemplate;

            //if (String.IsNullOrEmpty(SubmitContent.Email) || SubmitContent.Email.IndexOf("Anonymous e-mail", StringComparison.CurrentCultureIgnoreCase) >= 0)
            //{

            //    DNNGo_PowerForms_ContentItem ContentItem = ContentList.Find(r1 => r1.FieldName.IndexOf(Settings_SubmitUserEmail, StringComparison.CurrentCultureIgnoreCase) >= 0);

            //    if (ContentItem != null && !String.IsNullOrEmpty(ContentItem.ContentValue))
            //    {
            //        SubmitContent.Email = ContentItem.ContentValue;
            //    }
            //}

            EmailInfo Email = new EmailInfo();

            Email.Settings = Settings;
            Email.PushSettings(this);

            //1.构造管理员邮件并发送
            if (Settings_SendToAdmin && !String.IsNullOrEmpty(Settings_AdminEmail))//发邮件||管理员邮箱不为空
            {
                List <String> SendMailAddress = new List <string>();

                //Boolean ReplaceSender = Settings["PowerForms_ReplaceSender"] != null && !string.IsNullOrEmpty(Settings["PowerForms_ReplaceSender"].ToString()) ? Convert.ToBoolean(Settings["PowerForms_ReplaceSender"]) : false;
                //if (ReplaceSender && !String.IsNullOrEmpty(SubmitContent.Email) && Mail.IsValidEmailAddress(SubmitContent.Email, Null.NullInteger))
                //{
                //    Email.ReplyTo = SubmitContent.Email;//替换发件人地址为提交用户
                //}

                /** 因为要加入ReplyTo,这个需要记录下,屏蔽掉之前的代码  2015.12.21 **/
                String  EmailReplyTo = String.Empty;
                Boolean ReplyTo      = Settings["PowerForms_ReplyTo"] != null?Convert.ToBoolean(Settings["PowerForms_ReplyTo"]) : true;

                if (ReplyTo && !String.IsNullOrEmpty(SubmitContent.Email) && Mail.IsValidEmailAddress(SubmitContent.Email, Null.NullInteger))
                {
                    EmailReplyTo = SubmitContent.Email;//替换发件人地址为提交用户
                }

                //添加管理员邮件到代发列表
                if (!String.IsNullOrEmpty(Settings_AdminEmail))
                {
                    if (Settings_AdminEmail.IndexOf(";") >= 0)
                    {
                        List <String> adminMailTos = WebHelper.GetList(Settings_AdminEmail, ";");
                        foreach (var adminMailTo in adminMailTos)
                        {
                            if (!String.IsNullOrEmpty(adminMailTo) && Mail.IsValidEmailAddress(adminMailTo, Null.NullInteger))
                            {
                                SendMailAddress.Add(adminMailTo);
                            }
                        }
                    }
                    else
                    {
                        SendMailAddress.Add(Settings_AdminEmail);
                    }
                }



                //检索勾选的待发送角色
                String AdminEmailRoles = Settings["PowerForms_AdminEmailRoles"] != null?Convert.ToString(Settings["PowerForms_AdminEmailRoles"]) : "";

                if (!String.IsNullOrEmpty(AdminEmailRoles))
                {
                    List <String> RoleNames = Common.GetList(AdminEmailRoles);
                    if (RoleNames != null && RoleNames.Count > 0)
                    {
                        foreach (var RoleName in RoleNames)
                        {
                            if (!String.IsNullOrEmpty(RoleName))
                            {
                                //找出角色相关的用户信息
                                DotNetNuke.Security.Roles.RoleController roleController = new DotNetNuke.Security.Roles.RoleController();
                                ArrayList users = roleController.GetUsersByRoleName(PortalId, RoleName);
                                if (users != null && users.Count > 0)
                                {
                                    foreach (UserInfo user in users)
                                    {
                                        //判断邮件地址是否符合
                                        if (!String.IsNullOrEmpty(user.Email) && Mail.IsValidEmailAddress(user.Email, Null.NullInteger) && !(SendMailAddress.IndexOf(user.Email) >= 0))
                                        {
                                            SendMailAddress.Add(user.Email);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }



                //发送给所有的管理用户
                foreach (var SendMail in SendMailAddress)
                {
                    Email          = new EmailInfo();
                    Email.Settings = Settings;
                    Email.PushSettings(this);

                    if (!String.IsNullOrEmpty(EmailReplyTo))
                    {
                        Email.ReplyTo = EmailReplyTo;
                    }

                    //构造邮件的主题和内容
                    Email.Subject = FormatContent(SubmitContent, Template.ReceiversSubject, ContentList);
                    Email.Content = FormatContent(SubmitContent, Template.ReceiversTemplate, ContentList);

                    Email.MailTo = SendMail;
                    MailScheduler.AssignMessage(Email);//加到待发队列
                }
            }

            //2.构造提交者的邮件并发送
            if (Settings_SendToSubmitUser)
            {
                if (!String.IsNullOrEmpty(SubmitContent.Email) && SubmitContent.Email.IndexOf("Anonymous e-mail", StringComparison.CurrentCultureIgnoreCase) < 0)
                {
                    Email          = new EmailInfo();
                    Email.Settings = Settings;
                    Email.PushSettings(this);
                    Email.MailTo = SubmitContent.Email;

                    //构造邮件的主题和内容
                    Email.Subject = FormatContent(SubmitContent, Template.ReplySubject, ContentList);
                    Email.Content = FormatContent(SubmitContent, Template.ReplyTemplate, ContentList);

                    MailScheduler.AssignMessage(Email);//加到待发队列
                    //NetHelper.SendMail(Email);
                }
            }

            //3.检查有无下拉列表发邮件的字段
            foreach (DNNGo_PowerForms_Field fieldItem in FieldList)
            {
                if (fieldItem.FieldType == (Int32)EnumViewControlType.DropDownList_SendEmail)
                {
                    DNNGo_PowerForms_ContentItem contentItem = ContentList.Find(r1 => r1.FieldName == fieldItem.Name);
                    if (contentItem != null && !String.IsNullOrEmpty(contentItem.FieldName))
                    {
                        Email          = new EmailInfo();
                        Email.Settings = Settings;
                        Email.PushSettings(this);
                        Email.MailTo = contentItem.ContentValue;

                        //构造邮件的主题和内容
                        Email.Subject = FormatContent(SubmitContent, Template.ReceiversSubject, ContentList);
                        Email.Content = FormatContent(SubmitContent, Template.ReceiversTemplate, ContentList);

                        MailScheduler.AssignMessage(Email);//加到待发队列
                        //NetHelper.SendMail(Email);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 设置数据项
        /// </summary>
        private void SetDataItem()
        {
            #region "邮件设置"
            UpdateModuleSetting("PowerForms_AdminEmail", txtAdminEmail.Text.Trim());
            UpdateModuleSetting("PowerForms_SendToAdmin", cbSendToAdmin.Checked.ToString());
            UpdateModuleSetting("PowerForms_SendToSubmitUser", cbSendToSubmitUser.Checked.ToString());
            //UpdateModuleSetting("PowerForms_ReplaceSender", cbReplaceSender.Checked.ToString());
            UpdateModuleSetting("PowerForms_ReplyTo", cbReplyTo.Checked.ToString());

            if (ddlSubmitUserEmail.SelectedIndex >= 0)
            {
                UpdateModuleSetting("PowerForms_SubmitUserEmail", ddlSubmitUserEmail.Items[ddlSubmitUserEmail.SelectedIndex].Value);
            }


            String textStr, idStr = String.Empty;
            WebHelper.GetSelected(cblAdminEmailRoles, out textStr, out idStr);
            UpdateModuleSetting("PowerForms_AdminEmailRoles", idStr);



            //发件人邮箱
            UpdateModuleSetting("PowerForms_SenderEmail", txtSenderEmail.Text.Trim());

            DNNGo_PowerForms_Template Template = DNNGo_PowerForms_Template.FindByModuleId(ModuleId);
            Template.ReceiversSubject  = txtSendAdminTitle.Text.Trim();
            Template.ReceiversTemplate = txtSendAdminContent.Text.Trim();
            Template.ReplySubject      = txtSendSubmitUserTitle.Text.Trim();
            Template.ReplyTemplate     = txtSendSubmitUserContent.Text.Trim();

            Template.LastIP   = WebHelper.UserHost;
            Template.LastTime = xUserTime.UtcTime();
            Template.LastUser = UserId;

            if (Template != null && Template.ID > 0)
            {
                Template.Update();
            }
            else
            {
                Template.ModuleId = ModuleId;
                Template.Insert();
            }

            #endregion


            #region "定时邮件设置"
            DNNGo_PowerForms_Scheduler SchedulerItem = DNNGo_PowerForms_Scheduler.FindSettings(this);
            SchedulerItem.Enable      = cbScheduleEnable.Checked ? 1 : 0;
            SchedulerItem.ExcelName   = txtExcelName.Text.Trim();
            SchedulerItem.SenderEmail = txtScheduleSenderEmail.Text.Trim();
            DNNGo_PowerForms_Scheduler.UpdateSettings(SchedulerItem, this);


            //UpdateModuleSetting("PowerForms_Schedule_SenderEmail", txtScheduleSenderEmail.Text.Trim());
            //UpdateModuleSetting("PowerForms_Schedule_ExcelName", txtExcelName.Text.Trim());
            //UpdateModuleSetting("PowerForms_Schedule_Enable", cbScheduleEnable.Checked.ToString());


            if (cbScheduleEnable.Checked)//开启或创建调度器
            {
                SchedulerHelper sh = new SchedulerHelper();
                sh.UpdateScheduler(this);
            }


            #endregion
        }