Exemple #1
0
        public SendMail()
        {
            MessageEmailConfig config = EmailCore.GetConfig();

            setSmtpClient(config.SmtpServer, Convert.ToInt32(config.SmtpPort));
            setAddressform(config.SendAddress, config.Password, config.DisplayName);
        }
Exemple #2
0
        public void CheckCanEnable()
        {
            MessageEmailConfig config = EmailCore.GetConfig();

            if (string.IsNullOrWhiteSpace(config.SendAddress))
            {
                throw new PluginConfigException("未设置SMTP邮件地址");
            }
            if (!ValidateHelper.IsEmail(config.SendAddress))
            {
                throw new PluginConfigException("SMTP用户名填写错误");
            }
            if (string.IsNullOrWhiteSpace(config.EmailName))
            {
                throw new PluginConfigException("未设置SMTP邮箱用户名");
            }
            if (string.IsNullOrWhiteSpace(config.Password))
            {
                throw new PluginConfigException("未设置SMTP邮箱密码");
            }
            if (!ValidateHelper.IsNumeric(config.SmtpPort))
            {
                throw new PluginConfigException("SMTP端口错误");
            }
            if (string.IsNullOrWhiteSpace(config.SmtpServer))
            {
                throw new PluginConfigException("未设置SMTP邮箱服务器");
            }
            if (string.IsNullOrWhiteSpace(config.DisplayName))
            {
                throw new PluginConfigException("未设置SMTP邮箱显示名称");
            }
        }
Exemple #3
0
        public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values)
        {
            var SmtpServerItem = values.FirstOrDefault(item => item.Key == "SmtpServer");

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

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

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

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

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

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

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

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

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

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

            if (string.IsNullOrWhiteSpace(DisplayNameItem.Value))
            {
                throw new Himall.Core.PluginConfigException("SMTP显示名称不能为空");
            }
            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;
            EmailCore.SaveConfig(oldConfig);
        }
Exemple #4
0
        public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values)
        {
            KeyValuePair <string, string> keyValuePair = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "SmtpServer");

            if (string.IsNullOrWhiteSpace(keyValuePair.Value))
            {
                throw new PluginConfigException("SMTP服务器不能为空");
            }
            KeyValuePair <string, string> keyValuePair1 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "SmtpPort");

            if (!ValidateHelper.IsNumeric(keyValuePair1.Value))
            {
                throw new PluginConfigException("SMTP端口错误");
            }
            KeyValuePair <string, string> keyValuePair2 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "EmailName");

            if (string.IsNullOrWhiteSpace(keyValuePair2.Value))
            {
                throw new PluginConfigException("SMTP用户名不能为空");
            }
            KeyValuePair <string, string> keyValuePair3 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "Password");

            if (string.IsNullOrWhiteSpace(keyValuePair3.Value))
            {
                throw new PluginConfigException("SMTP密码不能为空");
            }
            KeyValuePair <string, string> keyValuePair4 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "SendAddress");

            if (string.IsNullOrWhiteSpace(keyValuePair4.Value))
            {
                throw new PluginConfigException("SMTP邮箱不能为空");
            }
            if (!ValidateHelper.IsEmail(keyValuePair4.Value))
            {
                throw new PluginConfigException("SMTP邮箱错误");
            }
            KeyValuePair <string, string> keyValuePair5 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "DisplayName");

            if (string.IsNullOrWhiteSpace(keyValuePair5.Value))
            {
                throw new PluginConfigException("SMTP显示名称不能为空");
            }
            MessageEmailConfig config = EmailCore.GetConfig();

            config.SmtpPort    = keyValuePair1.Value;
            config.SmtpServer  = keyValuePair.Value;
            config.EmailName   = keyValuePair2.Value;
            config.Password    = keyValuePair3.Value;
            config.SendAddress = keyValuePair4.Value;
            config.DisplayName = keyValuePair5.Value;
            EmailCore.SaveConfig(config);
        }
Exemple #5
0
        public FormData GetFormData()
        {
            MessageEmailConfig config    = EmailCore.GetConfig();
            FormData           formDatum = new FormData();

            FormData.FormItem[] formItemArray = new FormData.FormItem[6];
            FormData.FormItem   formItem      = new FormData.FormItem();
            formItem.DisplayName = "SMTP服务器";
            formItem.Name        = "SmtpServer";
            formItem.IsRequired  = true;
            formItem.Type        = FormData.FormItemType.text;
            formItem.Value       = config.SmtpServer;
            formItemArray[0]     = formItem;
            FormData.FormItem formItem1 = new FormData.FormItem();
            formItem1.DisplayName = "SMTP服务器端口";
            formItem1.Name        = "SmtpPort";
            formItem1.IsRequired  = true;
            formItem1.Type        = FormData.FormItemType.text;
            formItem1.Value       = config.SmtpPort;
            formItemArray[1]      = formItem1;
            FormData.FormItem formItem2 = new FormData.FormItem();
            formItem2.DisplayName = "SMTP用户名";
            formItem2.Name        = "EmailName";
            formItem2.IsRequired  = true;
            formItem2.Type        = FormData.FormItemType.text;
            formItem2.Value       = config.EmailName;
            formItemArray[2]      = formItem2;
            FormData.FormItem formItem3 = new FormData.FormItem();
            formItem3.DisplayName = "SMTP用户密码";
            formItem3.Name        = "Password";
            formItem3.IsRequired  = true;
            formItem3.Type        = FormData.FormItemType.password;
            formItem3.Value       = config.Password;
            formItemArray[3]      = formItem3;
            FormData.FormItem formItem4 = new FormData.FormItem();
            formItem4.DisplayName = "SMTP邮箱";
            formItem4.Name        = "SendAddress";
            formItem4.IsRequired  = true;
            formItem4.Type        = FormData.FormItemType.text;
            formItem4.Value       = config.SendAddress;
            formItemArray[4]      = formItem4;
            FormData.FormItem formItem5 = new FormData.FormItem();
            formItem5.DisplayName = "显示名称";
            formItem5.Name        = "DisplayName";
            formItem5.IsRequired  = true;
            formItem5.Type        = FormData.FormItemType.text;
            formItem5.Value       = config.DisplayName;
            formItemArray[5]      = formItem5;
            formDatum.Items       = formItemArray;
            return(formDatum);
        }
Exemple #6
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
                    }
                }
            };

            return(formData);
        }