예제 #1
0
        public void SendEmail(INotifications notifications, EmailSettingsModel settings, AlertModel alert)
        {
            string subject = PutObjectInTemplate(alert, settings.Template.Subject);
            string body    = PutObjectInTemplate(alert, settings.Template.Body);

            notifications.SendEmail(settings.Sender, settings.Recipient, subject, body);
        }
예제 #2
0
 public SettingsModel()
 {
     TimeSheetSettings = new TimeSheetSettings();
     EmailSettings     = new EmailSettingsModel();
     BlobSettings      = new BlobSettingsModel();
     DropBoxSettings   = new DropBoxSettings();
     SlackSettings     = new SlackSettingsModel();
     POCSettings       = new PointOfContactSettingsModel();
 }
예제 #3
0
 public void _CopyButton_Click()
 {
     if (SelectedEmailSettingsModel == null)
     {
         MessageBox.Show("Select a item to copy");
     }
     else
     {
         copiedEmailSettingsModel = SelectedEmailSettingsModel;
     }
 }
예제 #4
0
        public ActionResult EmailSettings()
        {
            if (!_permissionService.Authorize("ManageConfiguration"))
            {
                return(AccessDeniedView());
            }

            var model = new EmailSettingsModel();

            model.ActiveSettings = "EmailSettings";

            var emailSettings = _settingService.GetSettingsByType(SettingTypeEnum.EmailSetting).ToList();

            if (emailSettings.Count > 0)
            {
                foreach (var setting in emailSettings)
                {
                    if (setting.Name == "Host")
                    {
                        model.Host = setting.Value;
                    }
                    if (setting.Name == "Password")
                    {
                        model.Password = setting.Value;
                    }
                    if (setting.Name == "EnableSSL")
                    {
                        model.EnableSSL = setting.Value.ToLower() == "true" ? true : false;
                    }
                    if (setting.Name == "UseDefaultCredentials")
                    {
                        model.UseDefaultCredentials = setting.Value.ToLower() == "true" ? true : false;
                    }
                    if (setting.Name == "Port")
                    {
                        model.Port = Convert.ToInt32(setting.Value);
                    }
                    if (setting.Name == "Username")
                    {
                        model.Username = setting.Value;
                    }
                    if (setting.Name == "FromEmail")
                    {
                        model.FromEmail = setting.Value;
                    }
                }
            }

            return(View(model));
        }
        private EmailSettingsModel GetSettings()
        {
            var settings = new EmailSettingsModel
            {
                Email    = Sitecore.Configuration.Settings.GetSetting(SmtpMailSettings.Email),
                Host     = Sitecore.Configuration.Settings.GetSetting(SmtpMailSettings.Host),
                Password = Sitecore.Configuration.Settings.GetSetting(SmtpMailSettings.Password)
            };

            Throw.IfCondition(string.IsNullOrWhiteSpace(settings.Email), nameof(settings.Email), DefaultErrorMessage);
            Throw.IfCondition(string.IsNullOrWhiteSpace(settings.Host), nameof(settings.Host), DefaultErrorMessage);
            Throw.IfCondition(string.IsNullOrWhiteSpace(settings.Password), nameof(settings.Password), DefaultErrorMessage);

            var port = Sitecore.Configuration.Settings.GetSetting(SmtpMailSettings.Port);

            Throw.IfCondition(!int.TryParse(port, out var portIntValue), nameof(port), DefaultErrorMessage);

            settings.Port = portIntValue;

            return(settings);
        }
예제 #6
0
        public HttpResponseMessage DeleteEmailSettings(EmailSettingsModel _EmailSettingsModel)
        {
            try
            {
                bool conn = false;
                conn = db.Database.Exists();
                if (!conn)
                {
                    ConnectionTools.changeToLocalDB(db);
                    conn = db.Database.Exists();
                }

                if (conn)
                {
                    var updateSettings = (from a in db.TBL_EMAIL_SETTINGS
                                          where a.ID == _EmailSettingsModel.ID && a.IS_DELETE == false
                                          select a).FirstOrDefault();
                    if (updateSettings != null)
                    {
                        updateSettings.IS_DELETE = true;
                    }
                    db.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK, "OK"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.ExpectationFailed));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                ConnectionTools.ChangeToRemoteDB(db);
            }
        }
예제 #7
0
 public IActionResult SaveSettings(EmailSettingsModel emailSettings)
 {
     SaveSetting(emailSettings);
     return(R.Success.Result);
 }
예제 #8
0
 public HomeController(EmailSettingsModel _emailSender)
 {
     emailSender = _emailSender;
 }
        public static SettingsModel GetDefaultSettings()
        {
            GeneralSettingsModel general = new GeneralSettingsModel()
            {
                ThemeBase = new ThemeBaseModel
                {
                    Name        = "BaseLight",
                    DisplayName = "Light",
                    SourceUri   = "pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml"
                },
                ThemeAccent = new ThemeAccentModel
                {
                    Name      = "Cobalt",
                    ColorCode = "#FF0050EF",
                    SourceUri = "pack://application:,,,/MahApps.Metro;component/Styles/Accents/Cobalt.xaml"
                },
                TopMost = false
            };

            AlertSettingsModel alerts = new AlertSettingsModel()
            {
                BuyTypeColor                = media.Brushes.Green,
                SellTypeColor               = media.Brushes.Red,
                OtherTypesColor             = media.Brushes.Yellow,
                PriceColor                  = media.Brushes.SlateGray,
                SymbolColor                 = media.Brushes.DarkGoldenrod,
                TriggeredByColor            = media.Brushes.DeepPink,
                TimeFrameColor              = media.Brushes.DarkMagenta,
                TimeColor                   = media.Brushes.DimGray,
                MaxAlertNumber              = 100,
                MaxPriceDecimalPlacesNumber = 5,
                CommentFontModel            = new FontModel()
                {
                    Family = media.Fonts.SystemFontFamilies.FirstOrDefault(family => family.Source.Equals("Arial",
                                                                                                          StringComparison.InvariantCultureIgnoreCase)),
                    WeightModel = new FontWeightModel()
                    {
                        Name = "Normal", Weight = windows.FontWeights.Normal
                    },
                    StyleModel = new FontStyleModel()
                    {
                        Name = "Normal", Style = windows.FontStyles.Normal
                    },
                    Size = 20
                },
                TimeFormat = TimeFormat.TwentyFourHour,
                TimeZone   = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(tz => tz.BaseUtcOffset.Equals(DateTimeOffset.Now.Offset)),
            };

            SoundSettingsModel sound = new SoundSettingsModel();

            EmailSettingsModel email = new EmailSettingsModel()
            {
                Template        = GetDefaultEmailTemplate(),
                DefaultTemplate = GetDefaultEmailTemplate(),
            };

            TelegramSettingsModel telegram = new TelegramSettingsModel()
            {
                DefaultMessageTemplate = GetDefaultTelegramMessageTemplate(),
                MessageTemplate        = GetDefaultTelegramMessageTemplate(),
                Conversations          = new ObservableCollection <TelegramConversation>()
            };

            SettingsModel Settings = new SettingsModel()
            {
                General  = general,
                Alerts   = alerts,
                Sound    = sound,
                Email    = email,
                Telegram = telegram
            };

            return(Settings);
        }
예제 #10
0
        public async Task <ObservableCollection <EmailSettingsModel> > GetEmailsForUser()
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(GlobalData.gblApiAdress);
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));
            client.Timeout = new TimeSpan(500000000000);
            //long userId = 1;
            long userId = Convert.ToInt32(App.Current.Properties["User_Id"].ToString());
            HttpResponseMessage response = client.GetAsync("api/EmailSettingsAPI/GetEmailSettings?userId=" + userId + "").Result;

            if (response.IsSuccessStatusCode)
            {
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling     = NullValueHandling.Ignore,
                    MissingMemberHandling = MissingMemberHandling.Ignore
                };
                string str = await response.Content.ReadAsStringAsync();

                data = JsonConvert.DeserializeObject <EmailSettingsModel[]>(str, settings);
                tmpListGrid.Clear();
                for (int i = 0; i < data.Length; i++)
                {
                    tmpListGrid.Add(new EmailSettingsModel
                    {
                        BCC                 = data[i].BCC,
                        CC                  = data[i].CC,
                        EMAIL               = data[i].EMAIL,
                        ID                  = data[i].ID,
                        IS_GMAIL            = data[i].IS_GMAIL,
                        IS_REQ_ENCRYPT_CONN = data[i].IS_REQ_ENCRYPT_CONN,
                        NAME                = data[i].NAME,
                        PASSWORD            = data[i].PASSWORD,
                        SMTP_SERVER         = data[i].SMTP_SERVER,
                        SMTP_SERVER_PORT    = data[i].SMTP_SERVER_PORT,
                        USER_ID             = data[i].USER_ID,
                        USER_NAME           = data[i].USER_NAME,
                        MAIL_TYPE           = data[i].MAIL_TYPE,
                    });
                }
            }
            EmailSettingsModel tmpEmailSettingsModel;

            if (tmpListGrid.Count == 0)
            {
                tmpEmailSettingsModel           = new EmailSettingsModel();
                tmpEmailSettingsModel.MAIL_TYPE = "System Email";
                tmpListGrid.Add(tmpEmailSettingsModel);
                tmpEmailSettingsModel           = new EmailSettingsModel();
                tmpEmailSettingsModel.MAIL_TYPE = "Online Product Enquiry Email";
                tmpListGrid.Add(tmpEmailSettingsModel);
            }
            else if (tmpListGrid.Count == 1)
            {
                if (tmpListGrid[0].MAIL_TYPE == "System Email")
                {
                    tmpEmailSettingsModel           = new EmailSettingsModel();
                    tmpEmailSettingsModel.MAIL_TYPE = "Online Product Enquiry Email";
                    tmpListGrid.Add(tmpEmailSettingsModel);
                }
                else if (tmpListGrid[0].MAIL_TYPE == "Online Product Enquiry Email")
                {
                    tmpEmailSettingsModel           = new EmailSettingsModel();
                    tmpEmailSettingsModel.MAIL_TYPE = "System Email";
                    tmpListGrid.Add(tmpEmailSettingsModel);
                }
            }

            ListGrid = tmpListGrid;
            return(new ObservableCollection <EmailSettingsModel>(tmpListGrid));
        }
예제 #11
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EmailService" /> class.
 /// </summary>
 /// <param name="sendGridClient">The send grid client.</param>
 public EmailService(ISendGridClientWrapper sendGridClient)
 {
     _emailSettingsModel = sendGridClient.EmailSettingsModel;
     _sendGridClient     = sendGridClient.SendGridClient;
 }
예제 #12
0
 public AuthMessageSender(IOptions <EmailSettingsModel> emailSettings)
 {
     _emailSettings = emailSettings.Value;
 }
예제 #13
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="SendGridClientWrapper" /> class.
 /// </summary>
 /// <param name="emailSettingsModel">The email settings model.</param>
 public SendGridClientWrapper(IOptions <EmailSettingsModel> emailSettingsModel)
 {
     EmailSettingsModel = emailSettingsModel.Value;
     SendGridClient     = new SendGridClient(EmailSettingsModel.ApiKey);
 }
예제 #14
0
        public ActionResult EmailSettings(EmailSettingsModel model)
        {
            if (!_permissionService.Authorize("ManageConfiguration"))
            {
                return(AccessDeniedView());
            }

            var user = _userContext.CurrentUser;

            if (ModelState.IsValid)
            {
                var emailSettings = _settingService.GetSettingsByType(SettingTypeEnum.EmailSetting).ToList();
                if (emailSettings.Count > 0)
                {
                    foreach (Settings setting in emailSettings)
                    {
                        setting.ModifiedOn = DateTime.Now;
                        setting.UserId     = user.Id;
                        if (setting.Name == "Host")
                        {
                            setting.Value = model.Host;
                            _settingService.Update(setting);
                        }
                        if (setting.Name == "Password")
                        {
                            setting.Value = model.Password;
                            _settingService.Update(setting);
                        }
                        if (setting.Name == "EnableSSL")
                        {
                            setting.Value = model.EnableSSL == true ? "true" : "false";
                            _settingService.Update(setting);
                        }
                        if (setting.Name == "UseDefaultCredentials")
                        {
                            setting.Value = model.UseDefaultCredentials == true ? "true" : "false";
                            _settingService.Update(setting);
                        }
                        if (setting.Name == "Port")
                        {
                            setting.Value = model.Port.ToString();
                            _settingService.Update(setting);
                        }
                        if (setting.Name == "Username")
                        {
                            setting.Value = model.Username;
                            _settingService.Update(setting);
                        }
                        if (setting.Name == "FromEmail")
                        {
                            setting.Value = model.FromEmail;
                            _settingService.Update(setting);
                        }
                    }
                }
                else
                {
                    // Host
                    var _incServersetting = new Settings();
                    _incServersetting.EntityId    = 0;
                    _incServersetting.Value       = model.Host;
                    _incServersetting.Name        = "Host";
                    _incServersetting.SettingType = (int)SettingTypeEnum.EmailSetting;
                    _incServersetting.TypeId      = (int)SettingTypeEnum.EmailSetting;
                    _incServersetting.Entity      = "Email";
                    _incServersetting.user        = user;
                    _incServersetting.UserId      = user.Id;
                    _incServersetting.CreatedOn   = DateTime.Now;
                    _incServersetting.ModifiedOn  = DateTime.Now;
                    _settingService.Insert(_incServersetting);

                    // Password
                    var _incPasswordSetting = new Settings();
                    _incPasswordSetting.EntityId    = 0;
                    _incPasswordSetting.Value       = model.Password;
                    _incPasswordSetting.Name        = "Password";
                    _incPasswordSetting.SettingType = (int)SettingTypeEnum.EmailSetting;
                    _incPasswordSetting.TypeId      = (int)SettingTypeEnum.EmailSetting;
                    _incPasswordSetting.Entity      = "Email";
                    _incPasswordSetting.user        = user;
                    _incPasswordSetting.UserId      = user.Id;
                    _incPasswordSetting.CreatedOn   = DateTime.Now;
                    _incPasswordSetting.ModifiedOn  = DateTime.Now;
                    _settingService.Insert(_incPasswordSetting);

                    // EnableSSL
                    var _incRequireSSLSetting = new Settings();
                    _incRequireSSLSetting.EntityId    = 0;
                    _incRequireSSLSetting.Value       = model.EnableSSL ? "true" : "false";
                    _incRequireSSLSetting.Name        = "EnableSSL";
                    _incRequireSSLSetting.SettingType = (int)SettingTypeEnum.EmailSetting;
                    _incRequireSSLSetting.TypeId      = (int)SettingTypeEnum.EmailSetting;
                    _incRequireSSLSetting.Entity      = "Email";
                    _incRequireSSLSetting.user        = user;
                    _incRequireSSLSetting.UserId      = user.Id;
                    _incRequireSSLSetting.CreatedOn   = DateTime.Now;
                    _incRequireSSLSetting.ModifiedOn  = DateTime.Now;
                    _settingService.Insert(_incRequireSSLSetting);

                    // UseDefaultCredentials
                    var _incSMTPAuthenticationSetting = new Settings();
                    _incSMTPAuthenticationSetting.EntityId    = 0;
                    _incSMTPAuthenticationSetting.Value       = model.UseDefaultCredentials ? "true" : "false";
                    _incSMTPAuthenticationSetting.Name        = "UseDefaultCredentials";
                    _incSMTPAuthenticationSetting.SettingType = (int)SettingTypeEnum.EmailSetting;
                    _incSMTPAuthenticationSetting.TypeId      = (int)SettingTypeEnum.EmailSetting;
                    _incSMTPAuthenticationSetting.Entity      = "Email";
                    _incSMTPAuthenticationSetting.user        = user;
                    _incSMTPAuthenticationSetting.UserId      = user.Id;
                    _incSMTPAuthenticationSetting.CreatedOn   = DateTime.Now;
                    _incSMTPAuthenticationSetting.ModifiedOn  = DateTime.Now;
                    _settingService.Insert(_incSMTPAuthenticationSetting);

                    // Port
                    var _incSMTPportSetting = new Settings();
                    _incSMTPportSetting.EntityId    = 0;
                    _incSMTPportSetting.Value       = model.Port.ToString();
                    _incSMTPportSetting.Name        = "Port";
                    _incSMTPportSetting.SettingType = (int)SettingTypeEnum.EmailSetting;
                    _incSMTPportSetting.TypeId      = (int)SettingTypeEnum.EmailSetting;
                    _incSMTPportSetting.Entity      = "Email";
                    _incSMTPportSetting.user        = user;
                    _incSMTPportSetting.UserId      = user.Id;
                    _incSMTPportSetting.CreatedOn   = DateTime.Now;
                    _incSMTPportSetting.ModifiedOn  = DateTime.Now;
                    _settingService.Insert(_incSMTPportSetting);

                    // Username
                    var _incUsernameSetting = new Settings();
                    _incUsernameSetting.EntityId    = 0;
                    _incUsernameSetting.Value       = model.Username;
                    _incUsernameSetting.Name        = "Username";
                    _incUsernameSetting.SettingType = (int)SettingTypeEnum.EmailSetting;
                    _incUsernameSetting.TypeId      = (int)SettingTypeEnum.EmailSetting;
                    _incUsernameSetting.Entity      = "Email";
                    _incUsernameSetting.user        = user;
                    _incUsernameSetting.UserId      = user.Id;
                    _incUsernameSetting.CreatedOn   = DateTime.Now;
                    _incUsernameSetting.ModifiedOn  = DateTime.Now;
                    _settingService.Insert(_incUsernameSetting);

                    // FromEmail
                    var _incFromEmailSetting = new Settings();
                    _incFromEmailSetting.EntityId    = 0;
                    _incFromEmailSetting.Value       = model.FromEmail;
                    _incFromEmailSetting.Name        = "FromEmail";
                    _incFromEmailSetting.SettingType = (int)SettingTypeEnum.EmailSetting;
                    _incFromEmailSetting.TypeId      = (int)SettingTypeEnum.EmailSetting;
                    _incFromEmailSetting.Entity      = "Email";
                    _incFromEmailSetting.user        = user;
                    _incFromEmailSetting.UserId      = user.Id;
                    _incFromEmailSetting.CreatedOn   = DateTime.Now;
                    _incFromEmailSetting.ModifiedOn  = DateTime.Now;
                    _settingService.Insert(_incFromEmailSetting);
                }
            }

            SuccessNotification("Email Settings Saved Successfully.");
            model.ActiveSettings = "EmailSettings";
            return(View(model));
        }
예제 #15
0
        public HttpResponseMessage UpdateEmailSettings(EmailSettingsModel _EmailSettingsModel)
        {
            try
            {
                bool conn = false;
                conn = db.Database.Exists();
                if (!conn)
                {
                    ConnectionTools.changeToLocalDB(db);
                    conn = db.Database.Exists();
                }

                if (conn)
                {
                    var updateSettings = (from a in db.TBL_EMAIL_SETTINGS
                                          where a.ID == _EmailSettingsModel.ID && a.IS_DELETE == false
                                          select a).FirstOrDefault();
                    if (updateSettings == null)
                    {
                        updateSettings = new TBL_EMAIL_SETTINGS();

                        updateSettings.BCC                 = _EmailSettingsModel.BCC;
                        updateSettings.CC                  = _EmailSettingsModel.CC;
                        updateSettings.EMAIL               = _EmailSettingsModel.EMAIL;
                        updateSettings.IS_GMAIL            = _EmailSettingsModel.IS_GMAIL;
                        updateSettings.IS_REQ_ENCRYPT_CONN = _EmailSettingsModel.IS_REQ_ENCRYPT_CONN;
                        updateSettings.NAME                = _EmailSettingsModel.NAME;
                        updateSettings.PASSWORD            = _EmailSettingsModel.PASSWORD;
                        updateSettings.SMTP_SERVER         = _EmailSettingsModel.SMTP_SERVER;
                        updateSettings.SMTP_SERVER_PORT    = _EmailSettingsModel.SMTP_SERVER_PORT;
                        updateSettings.USER_ID             = _EmailSettingsModel.USER_ID;
                        updateSettings.USER_NAME           = _EmailSettingsModel.USER_NAME;
                        updateSettings.MAIL_TYPE           = _EmailSettingsModel.MAIL_TYPE;
                        updateSettings.IS_DELETE           = false;
                        db.TBL_EMAIL_SETTINGS.Add(updateSettings);
                    }
                    else
                    {
                        updateSettings.BCC                 = _EmailSettingsModel.BCC;
                        updateSettings.CC                  = _EmailSettingsModel.CC;
                        updateSettings.EMAIL               = _EmailSettingsModel.EMAIL;
                        updateSettings.IS_GMAIL            = _EmailSettingsModel.IS_GMAIL;
                        updateSettings.IS_REQ_ENCRYPT_CONN = _EmailSettingsModel.IS_REQ_ENCRYPT_CONN;
                        updateSettings.NAME                = _EmailSettingsModel.NAME;
                        updateSettings.PASSWORD            = _EmailSettingsModel.PASSWORD;
                        updateSettings.SMTP_SERVER         = _EmailSettingsModel.SMTP_SERVER;
                        updateSettings.SMTP_SERVER_PORT    = _EmailSettingsModel.SMTP_SERVER_PORT;
                        updateSettings.USER_ID             = _EmailSettingsModel.USER_ID;
                        updateSettings.USER_NAME           = _EmailSettingsModel.USER_NAME;
                        updateSettings.MAIL_TYPE           = _EmailSettingsModel.MAIL_TYPE;
                        updateSettings.IS_DELETE           = false;
                    }
                    db.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK, "OK"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.ExpectationFailed));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                ConnectionTools.ChangeToRemoteDB(db);
            }
        }