Esempio n. 1
0
 public EmailService(IOptions <SendGridSettings> sendGridSettings, IOptions <SmtpSettings> smtpSettings, IBackgroundJobClient backgroundJobClient, IEmailProviderFactoryHelper emailProviderFactoryHelper)
 {
     _sendGridSettings           = sendGridSettings.Value;
     _smtpSettings               = smtpSettings.Value;
     _backgroundJobClient        = backgroundJobClient;
     _emailProviderFactoryHelper = emailProviderFactoryHelper;
 }
Esempio n. 2
0
        public SendGridClient(IConfiguration configuration)
        {
            _sendGridSettings = new SendGridSettings();
            var sectionData = configuration.GetSection("SendGrid");

            sectionData.Bind(_sendGridSettings);
        }
Esempio n. 3
0
 public MailService(IConfiguration config)
 {
     sendGridSettings = config.GetSection("SendGrid")
                        .Get <SendGridSettings>();
     appSettings = config.GetSection("AppSettings")
                   .Get <AppSettings>();
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
 public EmailSender(ILogger <EmailSender> logger,
                    SendGridSettings sendgridSettings, SendGridClientOptions options, HttpClient httpClient) : base(options)
 {
     _logger           = logger;
     _sendgridSettings = sendgridSettings;
     HttpClient        = httpClient;
 }
Esempio n. 7
0
 protected static void Initialize()
 {
     SendGridClientMock          = new Mock <ISendGridClient>();
     EmailTemplateRepositoryMock = new Mock <IEmailTemplateRepository>();
     SendGridSettings            = new SendGridSettings();
     EmailMessenger = new SendGridEmailMessenger(SendGridClientMock.Object,
                                                 EmailTemplateRepositoryMock.Object, SendGridSettings);
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
        /// <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;
 }
Esempio n. 11
0
        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"]
            };
        }
Esempio n. 13
0
 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;
 }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
 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();
 }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        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;
 }
Esempio n. 19
0
    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);
        }
    }
Esempio n. 20
0
        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;
        }
Esempio n. 22
0
        // 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);
        }
Esempio n. 23
0
 public SendGrid(SendGridSettings settings)
 {
     _settings = settings;
 }
Esempio n. 24
0
 public EmailSender(IOptions <SendGridSettings> emailOptions)
 {
     Options = emailOptions.Value;
 }
Esempio n. 25
0
        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));
        }
Esempio n. 26
0
        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;
        }
Esempio n. 27
0
 public EmailSender(IOptions <SendGridSettings> sendGridSettings)
 {
     _sendGridSettings = sendGridSettings.Value;
 }
Esempio n. 28
0
        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));
        }
Esempio n. 29
0
        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));
        }
Esempio n. 30
0
 public SendGridEmailSender(SendGridSettings settings)
 {
     this.settings = settings;
 }
Esempio n. 31
0
 public SendGridEmailService(IOptions <SendGridSettings> settings)
 {
     _settings = settings.Value;
 }