Exemple #1
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);
            }));
        }