public EmailService(IOptions <SendGridSettings> sendGridSettings, IOptions <SmtpSettings> smtpSettings, IBackgroundJobClient backgroundJobClient, IEmailProviderFactoryHelper emailProviderFactoryHelper) { _sendGridSettings = sendGridSettings.Value; _smtpSettings = smtpSettings.Value; _backgroundJobClient = backgroundJobClient; _emailProviderFactoryHelper = emailProviderFactoryHelper; }
public SendGridClient(IConfiguration configuration) { _sendGridSettings = new SendGridSettings(); var sectionData = configuration.GetSection("SendGrid"); sectionData.Bind(_sendGridSettings); }
public MailService(IConfiguration config) { sendGridSettings = config.GetSection("SendGrid") .Get <SendGridSettings>(); appSettings = config.GetSection("AppSettings") .Get <AppSettings>(); }
protected SendGridSettings GetSettings() { SendGridSettings settings = new SendGridSettings(); ConnectionStringSettings connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName]; if (connectionString == null) { return(settings); } var keyValuePairs = connectionString.ConnectionString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .Where(kvp => kvp.Contains('=')) .Select(kvp => kvp.Split(new char[] { '=' }, 2)) .ToDictionary(kvp => kvp[0].Trim(), kvp => kvp[1].Trim(), StringComparer.InvariantCultureIgnoreCase); // Mandatory if (keyValuePairs.ContainsKey("username")) { settings.Username = keyValuePairs["username"]; } if (keyValuePairs.ContainsKey("password")) { settings.Password = keyValuePairs["password"]; } // Optional return(settings); }
public SendGridService(IOptions <SendGridSettings> sendGridSettings, IJwtService jwtService) { _sendGridSettings = sendGridSettings.Value; _sendGridClient = new SendGridClient(_sendGridSettings.ApiKey); _defaultFromEmailAddress = new EmailAddress("*****@*****.**", "Recipes @ Gardner Web and Tech"); _jwtService = jwtService; }
public EmailSender(ILogger <EmailSender> logger, SendGridSettings sendgridSettings, SendGridClientOptions options, HttpClient httpClient) : base(options) { _logger = logger; _sendgridSettings = sendgridSettings; HttpClient = httpClient; }
protected static void Initialize() { SendGridClientMock = new Mock <ISendGridClient>(); EmailTemplateRepositoryMock = new Mock <IEmailTemplateRepository>(); SendGridSettings = new SendGridSettings(); EmailMessenger = new SendGridEmailMessenger(SendGridClientMock.Object, EmailTemplateRepositoryMock.Object, SendGridSettings); }
public CognizantIdentity(IUserLogic userlogic, IOptions <SendGridSettings> sgSettings, IUserRepository userRepository, IJwtFactory jwtFactory) { _sgSettings = sgSettings.Value; _client = new SendGridClient(_sgSettings.APIKey); _userlogic = userlogic; _userRepository = userRepository; _jwtFactory = jwtFactory; }
/// <summary> /// SendGrid default constructor /// </summary> /// <param name="sendGridSettings"> /// </param> public SendGridMailProvider(SendGridSettings sendGridSettings = null) { var settings = sendGridSettings ?? new Settings().SendGrid; if (settings == null) { throw new SendGridSettingsException(); } _sendGridClient = new SendGridClient(settings.ApiKey); }
public NotificationService( ILogger <NotificationService> logger, SendGridSettings sendGridSettings, CourierSettings courierSettings, HttpClient httpClient) { this.logger = logger; this.sendGridSettings = sendGridSettings; this.courierSettings = courierSettings; this.httpClient = httpClient; }
public SendGridMailService(IOptions <SendGridSettings> settings) { _serializerSettings = new JsonSerializerSettings(); _serializerSettings.NullValueHandling = NullValueHandling.Ignore; _serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); _settings = settings.Value; _client = new HttpClient(); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _settings.ApiKey); }
public RuntimeSettingsSendGridSettingsProvider(IRuntimeSettings runtimeSettings) { if (runtimeSettings == null) { throw new ArgumentNullException(nameof(runtimeSettings)); } _settings = new SendGridSettings { ApiKey = runtimeSettings["SendGrid.ApiKey"] }; }
public HomeController(IMarketForecaster marketForecaster, IOptions <StripeSettings> stripeOptions, IOptions <SendGridSettings> sendGridOptions, IOptions <TwilioSettings> twilioOptions, IOptions <WazeForecastSettings> wazeOptions) { homeVM = new HomeVM(); this._marketForecaster = marketForecaster; _stripeOptions = stripeOptions.Value; _sendGridOptions = sendGridOptions.Value; _twilioOptions = twilioOptions.Value; _wazeOptions = wazeOptions.Value; }
public EnvironmentVerification VerifyEnvironment() { EnvironmentVerification env = new EnvironmentVerification(); SendGridSettings settings = GetSettings(); if (string.IsNullOrEmpty(settings.ApiKey)) { env.VerificationItems.Add(VerificationType.Error, "Missing api key setting for SendGrid."); } return(env); }
public static void AddEmailSender(this ContainerBuilder builder, SendGridSettings sendGridsettings) { builder.Register <IEmailSender>(context => { var logger = context.Resolve <ILogger <EmailSender> >(); var options = new SendGrid.SendGridClientOptions() { ApiKey = sendGridsettings.ApiKey }; return(new EmailSender(logger, sendGridsettings, options, new HttpClient())); }) .SingleInstance(); }
public void InstallServices(IServiceCollection services, IConfiguration configuration) { //Scoped services.AddScoped <IAuthenticationService, AuthenticationService>(); services.AddScoped <ISecurityService, SecurityService>(); //Transient services.AddTransient <IEmailService, EmailService>(); //SingleTone var sendGridSettings = new SendGridSettings(); configuration.Bind(nameof(SendGridSettings), sendGridSettings); services.AddSingleton(sendGridSettings); }
public EnvironmentVerification VerifyEnvironment() { EnvironmentVerification env = new EnvironmentVerification(); SendGridSettings settings = GetSettings(); if (string.IsNullOrEmpty(settings.Username)) { env.VerificationItems.Add(VerificationType.Error, "Missing username setting in SendGrid connection string."); } if (string.IsNullOrEmpty(settings.Password)) { env.VerificationItems.Add(VerificationType.Error, "Missing password setting in SendGrid connection string."); } return(env); }
public HomeController( IMarketForecaster marketForecaster, // IOptions<StripeSettings> stripeOptions, IOptions <SendGridSettings> sendGridOptions, IOptions <TwilioSettings> twilioOptions, IOptions <WazeForecastSettings> wazeOptions, ICreditValidator creditValidator ) { homeVM = new HomeVM(); _marketForecaster = marketForecaster; //_stripeOptions is commented because we are using it with ACTION INJECTION instead constructor Injection. //_stripeOptions = stripeOptions.Value; _sendGridOptions = sendGridOptions.Value; _twilioOptions = twilioOptions.Value; _wazeOptions = wazeOptions.Value; _creditValidator = creditValidator; }
public SendGridMailDispatchSession( Core.Mail.MailSettings mailSettings, SendGridSettings sendGridSettings, IPathResolver pathResolver ) { _mailSettings = mailSettings; _sendGridSettings = sendGridSettings; if (_mailSettings.SendMode == MailSendMode.LocalDrop) { _debugMailDispatchSession = new DebugMailDispatchSession(mailSettings, pathResolver); } else { _sendGridClient = new SendGridClient(_sendGridSettings.ApiKey); } }
public async Task <IActionResult> SendEmail() { var sendGridSettings = new SendGridSettings(); _configuration.GetSection(nameof(SendGridSettings)).Bind(sendGridSettings); var apiKey = sendGridSettings.SendGridKey; var client = new SendGridClient(apiKey); var from = new EmailAddress("*****@*****.**", "Example User"); var subject = "Sending with SendGrid is Fun"; var to = new EmailAddress("*****@*****.**", "Example User"); var plainTextContent = "and easy to do anywhere, even with C#"; var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>"; var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); var response = await client.SendEmailAsync(msg); return(Ok(response.Body.ReadAsStringAsync())); }
public HomeController(IMarketForecaster marketForecaster, ILogger <HomeController> logger, ICreditValidator creditValidator, ApplicationDbContext context, IOptions <WazeForecastSettings> wazeForecast, IOptions <StripeSettings> stripe, IOptions <SendGridSettings> sendGrid, IOptions <TwilioSettings> twilio) { _context = context; _creditValidator = creditValidator; _marketForecaster = marketForecaster; _logger = logger; _wazeForecast = wazeForecast.Value; _stripeOptions = stripe.Value; _sendGridOptions = sendGrid.Value; _twilioOptions = twilio.Value; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); InjectAuth(services); var mongoOptions = new MongoDbSettings(); Configuration.Bind("MongoDbSettings", mongoOptions); services.AddSingleton(mongoOptions); var sendgridsettings = new SendGridSettings(); Configuration.Bind("Sendgrid", sendgridsettings); services.AddSingleton(sendgridsettings); services.AddScoped(typeof(IMongoRepository <>), typeof(MongoRepository <>)); services.AddTransient <IOrganisationRepository, OrganisationRepository>(); services.AddTransient <IPendingOrganisationRepository, PendingOrganisationRepository>(); services.AddTransient <IKeyContactRepository, KeyContactRepository>(); services.AddTransient <IOrganisationMemberRepository, OrganisationMemberRepository>(); services.AddTransient <IPlaylistRepository, PlaylistRepository>(); services.AddTransient <IServiceRepository, ServiceRepository>(); services.AddTransient <ILocationRepository, LocationRepository>(); services.AddTransient <IUnAuthenticatedHttpAdapter, UnAuthenticatedHttpAdapter>(); services.AddTransient <IPostcodeServiceClient, PostcodeServiceClient>(); services.AddTransient <ILocationSearchServiceClient, LocationSearchServiceClient>(); services.AddTransient <ISendGridSender, SendGridSender>(); AddSearchIndexClient(services); var registerOptions = new RegisterManagmentOptions(); Configuration.Bind("RegisterManagementAPI", registerOptions); services.InjectRegisterManagementServiceClient(registerOptions); ApplySwaggerGen(services); }
public SendGrid(SendGridSettings settings) { _settings = settings; }
public EmailSender(IOptions <SendGridSettings> emailOptions) { Options = emailOptions.Value; }
public SendGridResult SendEmail(string senderName, string senderAddress, System.Net.Mail.MailAddress recipient, string subject, string htmlContent, string textContent, IEnumerable <AttachmentBase> attachments, SendGridSettings settings) { var recipients = new[] { recipient }; return(SendEmail(senderName, senderAddress, recipients, subject, htmlContent, textContent, attachments, settings)); }
protected SendGridSettings GetSettings() { SendGridSettings settings = new SendGridSettings(); ConnectionStringSettings connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName]; if(connectionString == null) return settings; var keyValuePairs = connectionString.ConnectionString.Split(new[]{';'}, StringSplitOptions.RemoveEmptyEntries) .Where(kvp => kvp.Contains('=')) .Select(kvp => kvp.Split(new char[] { '=' }, 2)) .ToDictionary(kvp => kvp[0].Trim(), kvp => kvp[1].Trim(), StringComparer.InvariantCultureIgnoreCase); // Mandatory if (keyValuePairs.ContainsKey("username")) settings.Username = keyValuePairs["username"]; if (keyValuePairs.ContainsKey("password")) settings.Password = keyValuePairs["password"]; // Optional return settings; }
public EmailSender(IOptions <SendGridSettings> sendGridSettings) { _sendGridSettings = sendGridSettings.Value; }
public SendGridResult SendEmail(string senderName, string senderAddress, IEnumerable <System.Net.Mail.MailAddress> recipients, string subject, string htmlContent, string textContent, IEnumerable <AttachmentBase> attachments, SendGridSettings settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (string.IsNullOrWhiteSpace(senderAddress)) { throw new ArgumentNullException(nameof(senderAddress), "You must specify the 'from' email address."); } if (recipients == null || !recipients.Any(r => r != null && !string.IsNullOrEmpty(r.Address))) { throw new ArgumentNullException(nameof(recipients), "You must specify at least one recipient."); } if (string.IsNullOrWhiteSpace(subject)) { throw new ArgumentNullException(nameof(subject), "You must specify the subject."); } if (string.IsNullOrWhiteSpace(htmlContent) && string.IsNullOrEmpty(textContent)) { throw new ArgumentException("You must specify the HTML content and/or the text content. We can't send an empty email."); } return(_context.SendEmail(senderName, senderAddress, recipients, subject, htmlContent, textContent, attachments, settings)); }
public SendGridResult SendEmail(string senderName, string senderAddress, string recipientName, string recipientAddress, string subject, string htmlContent, string textContent, IEnumerable <AttachmentBase> attachments, SendGridSettings settings) { var recipient = new MailAddress(recipientAddress, recipientName); return(SendEmail(senderName, senderAddress, recipient, subject, htmlContent, textContent, attachments, settings)); }
public SendGridEmailSender(SendGridSettings settings) { this.settings = settings; }
public SendGridEmailService(IOptions <SendGridSettings> settings) { _settings = settings.Value; }