Esempio n. 1
0
        public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values)
        {
            var SmtpServerItem = values.FirstOrDefault(item => item.Key == "SmtpServer");

            if (string.IsNullOrWhiteSpace(SmtpServerItem.Value))
            {
                throw new Mall.Core.PluginConfigException("SMTP服务器不能为空");
            }

            var SmtpPortItem = values.FirstOrDefault(item => item.Key == "SmtpPort");

            if (!Core.Helper.ValidateHelper.IsNumeric(SmtpPortItem.Value))
            {
                throw new Mall.Core.PluginConfigException("SMTP端口错误");
            }

            var EmailNameItem = values.FirstOrDefault(item => item.Key == "EmailName");

            if (string.IsNullOrWhiteSpace(EmailNameItem.Value))
            {
                throw new Mall.Core.PluginConfigException("SMTP用户名不能为空");
            }

            var PasswordItem = values.FirstOrDefault(item => item.Key == "Password");

            if (string.IsNullOrWhiteSpace(PasswordItem.Value))
            {
                throw new Mall.Core.PluginConfigException("SMTP密码不能为空");
            }

            var SendAddressItem = values.FirstOrDefault(item => item.Key == "SendAddress");

            if (string.IsNullOrWhiteSpace(SendAddressItem.Value))
            {
                throw new Mall.Core.PluginConfigException("SMTP邮箱不能为空");
            }

            if (!Core.Helper.ValidateHelper.IsEmail(SendAddressItem.Value))
            {
                throw new Mall.Core.PluginConfigException("SMTP邮箱错误");
            }
            var DisplayNameItem = values.FirstOrDefault(item => item.Key == "DisplayName");

            if (string.IsNullOrWhiteSpace(DisplayNameItem.Value))
            {
                throw new Mall.Core.PluginConfigException("SMTP显示名称不能为空");
            }
            var EnableSsl = values.FirstOrDefault(item => item.Key == "EnableSsl");

            MessageEmailConfig oldConfig = EmailCore.GetConfig();

            oldConfig.SmtpPort    = SmtpPortItem.Value;
            oldConfig.SmtpServer  = SmtpServerItem.Value;
            oldConfig.EmailName   = EmailNameItem.Value;
            oldConfig.Password    = PasswordItem.Value;
            oldConfig.SendAddress = SendAddressItem.Value;
            oldConfig.DisplayName = DisplayNameItem.Value;
            oldConfig.EnableSsl   = string.IsNullOrWhiteSpace(EnableSsl.Value) ? false : bool.Parse(EnableSsl.Value);
            EmailCore.SaveConfig(oldConfig);
        }
Esempio n. 2
0
        public void CheckCanEnable()
        {
            MessageEmailConfig config = EmailCore.GetConfig();

            if (string.IsNullOrWhiteSpace(config.SendAddress))
            {
                throw new Mall.Core.PluginConfigException("未设置SMTP邮件地址");
            }
            if (!Core.Helper.ValidateHelper.IsEmail(config.SendAddress))
            {
                throw new Mall.Core.PluginConfigException("SMTP用户名填写错误");
            }
            if (string.IsNullOrWhiteSpace(config.EmailName))
            {
                throw new Mall.Core.PluginConfigException("未设置SMTP邮箱用户名");
            }
            if (string.IsNullOrWhiteSpace(config.Password))
            {
                throw new Mall.Core.PluginConfigException("未设置SMTP邮箱密码");
            }
            if (!Core.Helper.ValidateHelper.IsNumeric(config.SmtpPort))
            {
                throw new Mall.Core.PluginConfigException("SMTP端口错误");
            }
            if (string.IsNullOrWhiteSpace(config.SmtpServer))
            {
                throw new Mall.Core.PluginConfigException("未设置SMTP邮箱服务器");
            }
            if (string.IsNullOrWhiteSpace(config.DisplayName))
            {
                throw new Mall.Core.PluginConfigException("未设置SMTP邮箱显示名称");
            }
        }
Esempio n. 3
0
        public SendMail()
        {
            MessageEmailConfig config = EmailCore.GetConfig();

            setSmtpClient(config.SmtpServer, Convert.ToInt32(config.SmtpPort));
            setAddressform(config.SendAddress, config.Password, config.DisplayName);
        }
Esempio n. 4
0
        public Core.Plugins.FormData GetFormData()
        {
            var config = EmailCore.GetConfig();

            var formData = new Core.Plugins.FormData()
            {
                Items = new Core.Plugins.FormData.FormItem[] {
                    //SmtpServer
                    new  Core.Plugins.FormData.FormItem()
                    {
                        DisplayName = "SMTP服务器",
                        Name        = "SmtpServer",
                        IsRequired  = true,
                        Type        = Core.Plugins.FormData.FormItemType.text,
                        Value       = config.SmtpServer
                    },
                    new  Core.Plugins.FormData.FormItem()
                    {
                        DisplayName = "SMTP服务器端口",
                        Name        = "SmtpPort",
                        IsRequired  = true,
                        Type        = Core.Plugins.FormData.FormItemType.text,
                        Value       = config.SmtpPort
                    },
                    new  Core.Plugins.FormData.FormItem()
                    {
                        DisplayName = "SMTP用户名",
                        Name        = "EmailName",
                        IsRequired  = true,
                        Type        = Core.Plugins.FormData.FormItemType.text,
                        Value       = config.EmailName
                    },
                    new  Core.Plugins.FormData.FormItem()
                    {
                        DisplayName = "SMTP用户密码",
                        Name        = "Password",
                        IsRequired  = true,
                        Type        = Core.Plugins.FormData.FormItemType.password,
                        Value       = config.Password
                    },
                    new  Core.Plugins.FormData.FormItem()
                    {
                        DisplayName = "SMTP邮箱",
                        Name        = "SendAddress",
                        IsRequired  = true,
                        Type        = Core.Plugins.FormData.FormItemType.text,
                        Value       = config.SendAddress
                    },
                    new  Core.Plugins.FormData.FormItem()
                    {
                        DisplayName = "显示名称",
                        Name        = "DisplayName",
                        IsRequired  = true,
                        Type        = Core.Plugins.FormData.FormItemType.text,
                        Value       = config.DisplayName
                    },
                    new  Core.Plugins.FormData.FormItem()
                    {
                        DisplayName = "开启SSL",
                        Name        = "EnableSsl",
                        IsRequired  = true,
                        Type        = Core.Plugins.FormData.FormItemType.checkbox,
                        Value       = config.EnableSsl.ToString()
                    }
                }
            };

            return(formData);
        }