public EmailService(SMTPModel model) { _client.UseDefaultCredentials = false; _client.Credentials = new NetworkCredential(model.UserName, model.Password); _client.Host = model.Host; _client.Port = model.Port; _client.DeliveryMethod = SmtpDeliveryMethod.Network; _client.EnableSsl = model.EnableSSL; }
public Startup(IConfiguration configuration) { Configuration = configuration; SMTPModel.LoadSettings(configuration); }
public Startup(IConfiguration configuration) { Configuration = configuration; SMTPModel.SetConf(Configuration); }
public EmailService(IOptions <SMTPModel> smptOptions, IUserService userService) { _userService = userService; _smtpOptions = smptOptions.Value; }
public SmtpClient SMTPConfigSettings(SmtpClient SmtpServerConfig, SMTPModel _configSettings) { string SmtpMethodLocal = ""; string SMTPServerConfigPickupDirectoryLocation = ""; string SMTPServerConfigHost = ""; Int32 SMTPServerConfigPort = 0; bool SMTPServerConfigUseDefaultCredentials = false; bool SMTPServerConfigEnableSsl = false; string SMTPServerConfigUsername = ""; string SMTPServerConfigPassword = ""; bool checkifSmtpMethodLocalIsSet = false; bool checkifSMTPServerConfigPickupDirectoryLocationIsSet = false; bool checkifSMTPServerConfigHostIsSet = false; bool checkifSMTPServerConfigPortIsSet = false; try { SmtpMethodLocal = _configSettings.SMTPServerUseLocalDir.ToLower(); checkifSmtpMethodLocalIsSet = true; } catch { SmtpMethodLocal = "true"; } try { SMTPServerConfigPickupDirectoryLocation = _configSettings.SMTPServerConfigPickupDirectoryLocation.ToLower(); checkifSMTPServerConfigPickupDirectoryLocationIsSet = true; } catch { SMTPServerConfigPickupDirectoryLocation = @"C:\temp\"; } try { SMTPServerConfigHost = _configSettings.SMTPServerConfigHost.ToLower(); checkifSMTPServerConfigHostIsSet = true; } catch { SMTPServerConfigHost = ""; } try { SMTPServerConfigPort = Convert.ToInt32(_configSettings.SMTPServerConfigPort); checkifSMTPServerConfigPortIsSet = true; } catch { SMTPServerConfigPort = 25; //Default Smtp Port } try { string useDefaultCredentials = _configSettings.SMTPServerConfigUseDefaultCredentials.ToLower(); SMTPServerConfigUseDefaultCredentials = useDefaultCredentials == "false" || useDefaultCredentials == "true" ? Convert.ToBoolean(useDefaultCredentials) : true; } catch { SMTPServerConfigUseDefaultCredentials = false; } try { string enableSsl = _configSettings.SMTPServerConfigEnableSsl.ToLower(); SMTPServerConfigEnableSsl = enableSsl == "false" || enableSsl == "true" ? Convert.ToBoolean(enableSsl) : true; } catch { SMTPServerConfigEnableSsl = true; } try { SMTPServerConfigUsername = _configSettings.SMTPServerConfigUsername.ToLower(); } catch { SMTPServerConfigUsername = "******"; } try { SMTPServerConfigPassword = _configSettings.SMTPServerConfigPassword.ToLower(); } catch { SMTPServerConfigPassword = "******"; } bool UseLocal = SmtpMethodLocal == "false" || SmtpMethodLocal == "true" ? Convert.ToBoolean(SmtpMethodLocal) : true; if ((UseLocal && checkifSMTPServerConfigPickupDirectoryLocationIsSet && checkifSmtpMethodLocalIsSet) || (!UseLocal && checkifSMTPServerConfigHostIsSet && checkifSMTPServerConfigPortIsSet) ) { if (UseLocal) { SmtpServerConfig.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory; SmtpServerConfig.PickupDirectoryLocation = SMTPServerConfigPickupDirectoryLocation; } else { SmtpServerConfig.Host = SMTPServerConfigHost; SmtpServerConfig.Port = SMTPServerConfigPort; SmtpServerConfig.UseDefaultCredentials = SMTPServerConfigUseDefaultCredentials; SmtpServerConfig.EnableSsl = SMTPServerConfigEnableSsl; SmtpServerConfig.DeliveryFormat = System.Net.Mail.SmtpDeliveryFormat.SevenBit; SmtpServerConfig.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; if (!SMTPServerConfigUseDefaultCredentials) { SmtpServerConfig.Credentials = new NetworkCredential { UserName = SMTPServerConfigUsername, Password = SMTPServerConfigPassword }; } } } return(SmtpServerConfig); }