public EmailAdminNotifier(IOptions <SendGridConfig> sendGridConfiguration,
                           IOptions <AdminContactInfo> adminContactInfo)
 {
     this.adminContactInfo = adminContactInfo.Value;
     this.sendGridSettings = sendGridConfiguration.Value;
     this.sendGridApi      = new Web(sendGridConfiguration.Value.Key);
 }
Example #2
0
        private SendGridService GetSendGridService()
        {
            var apiKey         = "";
            var sendGridConifg = new SendGridConfig(apiKey);
            var service        = new SendGridService(sendGridConifg);

            return(service);
        }
Example #3
0
        public static SendGridConfig GetConfigFromEnvVars()
        {
            SendGridConfig sendGridConfig = new SendGridConfig();

            sendGridConfig.sendGridApiUser = Environment.GetEnvironmentVariable("SendGrid_ApiUser");
            sendGridConfig.sendGridApiKey  = Environment.GetEnvironmentVariable("SendGrid_ApiKey");

            if (sendGridConfig.sendGridApiKey == null || sendGridConfig.sendGridApiUser == null)
            {
                throw new Exception("SendGrid configuration not found in environment vars or incomplete");
            }

            return(sendGridConfig);
        }
Example #4
0
 public UserApiController(IUserTokenService userTokenService
                          , IUserService userService
                          , IAuthenticationService <int> authService
                          , ILogger <TempAuthApiController> logger
                          , IOptions <SecurityConfig> options
                          , IOptions <SendGridConfig> sendGridConfig
                          , IEmailService service) : base(logger)
 {
     _service          = service;
     _sendGridConfig   = sendGridConfig.Value;
     _userService      = userService;
     _userTokenService = userTokenService;
     _authService      = authService;
     _options          = options;
 }
Example #5
0
        public void InitializeTest()
        {
            _sendGridConfig = new SendGridConfig()
            {
                ApiKey             = "YOUR-API-KEY",
                SenderEmailAddress = "YOUR-CATCHALL-EMAIL-ADDRESS",
                SenderEmailName    = "Do Not Reply",
                TemplateId         = "SENDGRID-TEMPLATE-ID"
            };

            _images = new Dictionary <string, string>()
            {
                { "TestImage1.jpg", "Images\\TestImage1.jpg" },
                { "TestImage21.jpg", "Images\\TestImage2.jpg" }
            };
        }
        async static Task Main(string[] args)
        {
            string             currentDirectory = Environment.CurrentDirectory;
            IConfigurationRoot config           = new ConfigurationBuilder()
                                                  .SetBasePath(currentDirectory)
                                                  .AddJsonFile("appsettings.json", true)
                                                  .Build();

            CosmosConfig   cosmosConfig   = config.GetSection("CosmosConfig").Get <CosmosConfig>();
            SendGridConfig sendGridConfig = config.GetSection("SendGridConfig").Get <SendGridConfig>();

            SendGridClient  sgc             = new SendGridClient(sendGridConfig.ApiKey);
            CosmosDbService cosmosDbService = InitializeCosmosClientInstance(cosmosConfig);

            EmailTemplateUploader emailTemplateUploader = new EmailTemplateUploader(
                sgc,
                cosmosDbService
                );

            await emailTemplateUploader.Migrate();
        }
Example #7
0
 public EmailService(IOptions <SendGridConfig> options, IOptions <SiteConfig> siteConfig, IPasswordService passwordService)
 {
     _config          = options.Value;
     _siteConfig      = siteConfig.Value;
     _passwordService = passwordService;
 }
Example #8
0
 public SendGridService(IOptions <AppConfig> _appSettings)
 {
     appSettings    = _appSettings.Value;
     sendGridConfig = appSettings.SendGrid;
     sendGridClient = new SendGridClient(sendGridConfig.ApiKey);
 }
        public void SetUp()
        {
            _sendGridConfigSettings = new SendGridConfig()
            {
                ApiKey    = "TestKey",
                FromName  = "Test Name",
                FromEmail = "Test Email",
                BaseUrl   = "Base Url"
            };

            _sendGridConfig = new Mock <IOptions <SendGridConfig> >();
            _sendGridConfig.SetupGet(x => x.Value).Returns(_sendGridConfigSettings);
            _sendGridClient = new Mock <ISendGridClient>();
            _templateId     = "testTemplateId";

            Templates templates = new Templates();
            Template  template  = new Template()
            {
                id   = _templateId,
                name = "KnownTemplate"
            };

            templates.templates = new Template[1]
            {
                template
            };
            string responseBody = JsonConvert.SerializeObject(templates);

            _templatesResponse = Task.FromResult(new Response(System.Net.HttpStatusCode.OK, new StringContent(responseBody), null));

            _sendGridClient.Setup(x => x.RequestAsync(
                                      It.IsAny <SendGridClient.Method>(),
                                      It.IsAny <string>(),
                                      It.IsAny <string>(),
                                      It.Is <String>(s => s.Contains("templates")),
                                      It.IsAny <CancellationToken>()))
            .Returns(() => _templatesResponse
                     );

            _memCacheTemplate = new Mock <IMemDistCache <Template> >();
            _template         = template;

            _memCacheTemplate.Setup(x => x.GetCachedDataAsync(
                                        It.IsAny <Func <CancellationToken, Task <Template> > >(),
                                        It.IsAny <string>(), It.IsAny <RefreshBehaviour>(),
                                        It.IsAny <CancellationToken>(),
                                        It.IsAny <NotInCacheBehaviour>()))
            .ReturnsAsync(() => _template);

            _memCacheUnsubscribeGroup = new Mock <IMemDistCache <UnsubscribeGroup> >();

            _unsubscribeGroup = new UnsubscribeGroup()
            {
                id = -1
            };

            _memCacheUnsubscribeGroup.Setup(x => x.GetCachedDataAsync(
                                                It.IsAny <Func <CancellationToken, Task <UnsubscribeGroup> > >(),
                                                It.IsAny <string>(), It.IsAny <RefreshBehaviour>(),
                                                It.IsAny <CancellationToken>(),
                                                It.IsAny <NotInCacheBehaviour>()))
            .ReturnsAsync(() => _unsubscribeGroup);


            UnsubscribeGroup[] groups = new UnsubscribeGroup[1];
            groups[0] = new UnsubscribeGroup()
            {
                id          = 1,
                name        = "KnownGroup",
                description = "KnownGroup description"
            };
            string groupsResponseBody = JsonConvert.SerializeObject(groups);

            _groupsResponse = Task.FromResult(new Response(System.Net.HttpStatusCode.OK, new StringContent(groupsResponseBody), null));

            _sendGridClient.Setup(x => x.RequestAsync(
                                      It.IsAny <SendGridClient.Method>(),
                                      It.IsAny <string>(),
                                      It.IsAny <string>(),
                                      It.Is <String>(s => s.Contains("groups")),
                                      It.IsAny <CancellationToken>()))
            .Returns(() => _groupsResponse
                     );


            _sendGridClient.Setup(x => x.SendEmailAsync(
                                      It.IsAny <SendGridMessage>(),
                                      It.IsAny <CancellationToken>()
                                      )).Returns(() => _sendEmailResponse);

            _classUnderTest = new ConnectSendGridService(_sendGridConfig.Object, _sendGridClient.Object, _memCacheTemplate.Object, _memCacheUnsubscribeGroup.Object);
        }
 public EmailService(IOptions <SendGridConfig> options)
 {
     _config = options.Value;
 }
Example #11
0
 public void SetConfig(SenderConfiguration senderConfiguration)
 {
     _option = senderConfiguration.SendGrid;
 }
Example #12
0
 public SendGridService(SendGridConfig smtpOptions)
 {
     _smtpOptions = smtpOptions;
 }
Example #13
0
 public EmailService(IOptions <SendGridConfig> config)
 {
     _config = config.Value;
 }