protected SmtpClient GetSmtpClient(CustomSmtpModel customSmtp)
        {
            var smtpClient = new SmtpClient();

            var smtpServerSetting   = Settings.GetSetting("MailServer");
            var smtpUserNameSetting = Settings.GetSetting("MailServerUserName");
            var smtpPasswordSetting = Settings.GetSetting("MailServerPassword");
            var smtpPortSetting     = Settings.GetIntSetting("MailServerPort", 0);

            if (!string.IsNullOrWhiteSpace(smtpServerSetting))
            {
                smtpClient.Host = smtpServerSetting;
            }

            //Custom SMTP Host override
            if (!string.IsNullOrWhiteSpace(customSmtp.Host))
            {
                smtpClient.Host = customSmtp.Host;
            }

            if (!string.IsNullOrWhiteSpace(smtpUserNameSetting))
            {
                smtpClient.Credentials = new NetworkCredential(smtpUserNameSetting, !string.IsNullOrWhiteSpace(smtpPasswordSetting) ? smtpPasswordSetting : string.Empty);
            }

            //Custom SMTP credentials (Login, Password) override
            if (!string.IsNullOrWhiteSpace(customSmtp.Login))
            {
                smtpClient.Credentials = new NetworkCredential(customSmtp.Login, !string.IsNullOrWhiteSpace(customSmtp.Password) ? customSmtp.Password : string.Empty);
            }

            if (smtpPortSetting > 0)
            {
                smtpClient.Port = smtpPortSetting;
            }

            //Custom SMTP Port override
            if (customSmtp.Port > 0)
            {
                smtpClient.Port = customSmtp.Port;
            }

            //Custom SMTP EnableSsl override
            if (customSmtp.EnableSsl != null)
            {
                smtpClient.EnableSsl = customSmtp.EnableSsl.Value;
            }

            return(smtpClient);
        }
        protected CustomSmtpModel ParseSmtpSettings(string settingsField)
        {
            var customSmtp = new CustomSmtpModel();

            if (string.IsNullOrWhiteSpace(settingsField))
            {
                return(customSmtp);
            }

            var finalXml   = $"<CustomSmtpModel>{settingsField}</CustomSmtpModel>";
            var serializer = new XmlSerializer(typeof(CustomSmtpModel));

            using (var reader = new StringReader(finalXml))
            {
                customSmtp = (CustomSmtpModel)serializer.Deserialize(reader);
            }

            return(customSmtp);
        }
 internal SmtpClient InvokeGetSmtpClient(CustomSmtpModel customSmtp)
 {
     return(GetSmtpClient(customSmtp));
 }