public GroupEmailBuilder(ILogger <GroupEmailBuilder> logger,
                          IHttpEmailClient emailClient,
                          IApplicationConfiguration configuration,
                          BusinessId businessId)
 {
     _logger        = logger;
     _configuration = configuration;
     _businessId    = businessId;
     _emailClient   = emailClient;
     _fromEmail     = _configuration.GetEmailEmailFrom(_businessId.ToString()).IsValid()
         ? _configuration.GetEmailEmailFrom(_businessId.ToString()).ToString()
         : string.Empty;
 }
Esempio n. 2
0
        public async Task HandleStaleGroups()
        {
            var allGroups = await _stockportApiRepository.GetResponse <List <Group> >();

            if (allGroups == null || !allGroups.Any())
            {
                throw new GroupsServiceException("No groups were returned from content api");
            }

            _logger.LogInformation($"Returned {allGroups.Count} groups");

            var emailPeriods = _configuration.GetArchiveEmailPeriods();

            if (emailPeriods == null || !emailPeriods.Any())
            {
                throw new GroupsServiceException("No periods returned from the service");
            }

            var fromAddress = _configuration.GetEmailEmailFrom("stockportgov");

            foreach (var period in emailPeriods)
            {
                var stagedGroups = FilterGroupsByStage(allGroups, period.NumOfDays);

                if (period.NumOfDays == emailPeriods.Select(p => p.NumOfDays).Max())
                {
                    var loopExceptions = new List <Exception>();
                    foreach (var group in stagedGroups)
                    {
                        try
                        {
                            ArchiveGroup(group);
                        }
                        catch (Exception e)
                        {
                            loopExceptions.Add(e);
                        }
                    }

                    foreach (var exception in loopExceptions)
                    {
                        _logger.LogError(exception.Message);
                    }
                }

                SendEmailToGroups(stagedGroups, period.Template, period.Subject, fromAddress.ToString());
            }
        }
Esempio n. 3
0
        private Task <HttpStatusCode> SendEmailMessage(ContactUsDetails contactUsDetails)
        {
            var messageSubject = $"{contactUsDetails.Title} - {contactUsDetails.Subject}";

            _logger.LogDebug("Sending contact us form email");

            var fromEmail = _applicationConfiguration.GetEmailEmailFrom(_businessId.ToString()).IsValid()
                ? _applicationConfiguration.GetEmailEmailFrom(_businessId.ToString()).ToString()
                : string.Empty;

            return(_emailClient.SendEmailToService
                       (new EmailMessage(messageSubject,
                                         CreateMessageBody(contactUsDetails),
                                         fromEmail,
                                         contactUsDetails.ServiceEmail,
                                         contactUsDetails.Email,
                                         new List <IFormFile>())));
        }
Esempio n. 4
0
        public AmazonSesClientConfiguration Build(string businessId)
        {
            var host      = _config.GetEmailHost(businessId);
            var region    = _config.GetEmailRegion(businessId);
            var emailFrom = _config.GetEmailEmailFrom(businessId);

            return(new AmazonSesClientConfiguration(host, region,
                                                    emailFrom, _amazonKeys));
        }