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

            setSmtpClient(config.SmtpServer, Convert.ToInt32(config.SmtpPort));
            setAddressform(config.SendAddress, config.Password, config.DisplayName);
        }
Example #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邮箱显示名称");
            }
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
0
        public static void SaveConfig(MessageEmailConfig config)
        {
            FileStream fileStream = new FileStream(string.Concat(EmailCore.WorkDirectory, "\\Data\\Email.config"), FileMode.Create);

            try
            {
                (new XmlSerializer(typeof(MessageEmailConfig))).Serialize(fileStream, config);
            }
            finally
            {
                if (fileStream != null)
                {
                    ((IDisposable)fileStream).Dispose();
                }
            }
        }