Beispiel #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);
        }
Beispiel #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邮箱显示名称");
            }
        }
Beispiel #3
0
        public SendMail()
        {
            MessageEmailConfig config = EmailCore.GetConfig();

            setSmtpClient(config.SmtpServer, Convert.ToInt32(config.SmtpPort));
            setAddressform(config.SendAddress, config.Password, config.DisplayName);
        }
Beispiel #4
0
        /// <summary>
        /// 保存配置
        /// </summary>
        /// <param name="config"></param>
        public static void SaveConfig(MessageEmailConfig config)
        {
            //using (FileStream fs = new FileStream(WorkDirectory + "\\Data\\Email.config", FileMode.Create))
            //{
            //    XmlSerializer xs = new XmlSerializer(typeof(MessageEmailConfig));
            //    xs.Serialize(fs, config);
            //}

            string        sDirectory = Mall.Core.Helper.IOHelper.urlToVirtual(WorkDirectory) + "/Data/Email.config";
            XmlSerializer xml        = new XmlSerializer(typeof(MessageEmailConfig));
            MemoryStream  Stream     = new MemoryStream();

            xml.Serialize(Stream, config);

            byte[]       b       = Stream.ToArray();
            MemoryStream stream2 = new MemoryStream(b);

            Mall.Core.MallIO.CreateFile(sDirectory, stream2, Core.FileCreateType.Create);
        }
Beispiel #5
0
        /// <summary>
        /// 获取配置
        /// </summary>
        /// <returns></returns>
        public static MessageEmailConfig GetConfig()
        {
            Log.Info("email1---sss");
            string             sDirectory = Mall.Core.Helper.IOHelper.urlToVirtual(WorkDirectory) + "/Data/Email.config";
            MessageEmailConfig config     = new MessageEmailConfig();

            if (MallIO.ExistFile(sDirectory))
            {
                XmlSerializer xs  = new XmlSerializer(typeof(MessageEmailConfig));
                byte[]        b   = Mall.Core.MallIO.GetFileContent(sDirectory);
                string        str = System.Text.Encoding.Default.GetString(b);
                MemoryStream  fs  = new MemoryStream(b);
                config = (MessageEmailConfig)xs.Deserialize(fs);
            }
            else
            {
                SaveConfig(config);
            }

            Log.Info("email1---eee");
            return(config);
        }