Пример #1
0
        public PortalSmtpSettingsDto GetSmtpSettings()
        {
            var rohamConfigs = _rohamConfigsResolver();
            var result       = new PortalSmtpSettingsDto
            {
                SmtpEnabled  = rohamConfigs.SmtpEnabled,
                SmtpHost     = rohamConfigs.SmtpHost,
                SmtpPort     = rohamConfigs.SmtpPort,
                SmtpUsername = rohamConfigs.SmtpUsername,
                SmtpPassword = rohamConfigs.SmtpPassword,
                SmtpDomain   = rohamConfigs.SmtpDomain,
                SmtpUseSsl   = rohamConfigs.SmtpEnableSsl,
                SmtpFrom     = rohamConfigs.SmtpFrom
            };

            return(result);
        }
Пример #2
0
        public ResultDto SaveSmtpSettings(PortalSmtpSettingsDto smtpSettingsDto)
        {
            return(Result(() =>
            {
                var rohamConfigs = _rohamConfigsResolver();
                var rohamConfigsUpdater = rohamConfigs as IRohamConfigsUpdater;

                string errorMessage = "";
                var smtpSettings = smtpSettingsDto.ToSmtpSettings();
                if (smtpSettingsDto.SmtpEnabled)
                {
                    if (!Email.TryPingHost(smtpSettings.Host, smtpSettings.Port, out errorMessage))
                    {
                        throw new ValidationException($"Email server cannot be connected. {errorMessage}");
                    }
                }

                rohamConfigsUpdater.SetSmtp(smtpSettingsDto.SmtpEnabled, smtpSettings.Host, smtpSettings.Port, smtpSettings.EnableSsl,
                                            smtpSettings.UserName, smtpSettings.Password, smtpSettings.Domain, smtpSettingsDto.SmtpFrom);
            }));
        }