Example #1
0
        private async Task SendEmailAsync(JumpStart jumpStart)
        {
            var company = await _dbContext.Companies.FirstOrDefaultAsync(item => item.Name == VolkswagenCompany.Name);

            var pdfUrl = await _jumpStartPdfService.CreatePdfUrlAsync(jumpStart);

            var emailTemplate = _jumpStartEmailTemplateService.GetEmailHtml(jumpStart, jumpStart.Articles, pdfUrl);

            var recipients = await GetRecipients(jumpStart.Id);

            var subject =
                $"Project Blue Delta - {jumpStart.DateTime.InZone(VolkswagenCompany.TimeZoneId, "MMMM d, yyyy")}";

            foreach (var batch in recipients.Batch(SendGridService.BatchSize))
            {
                await _sendGridService.SendEmail(company.Id, batch, subject, emailTemplate, emailTemplate, jumpStart.DateTime);

                foreach (var recipient in batch)
                {
                    recipient.Status = EmailStatus.Sent;
                }

                await _dbContext.SaveChangesAsync();
            }
        }
Example #2
0
        private async Task SendEmailAsync(JumpStart jumpStart)
        {
            var company = await _dbContext.Companies.FirstOrDefaultAsync(item => item.Name == VolkswagenCompany.Name);

            var pdfUrl = await _jumpStartPdfService.CreatePdfUrlAsync(jumpStart);

            var emailTemplate = _jumpStartEmailTemplateService.GetEmailHtml(jumpStart.DateTime, jumpStart.Posts);

            var recipients = await GetRecipients(jumpStart.Id);

            var subject =
                $"Project Blue Delta - {jumpStart.DateTime.InZone(VolkswagenCompany.TimeZoneId, "MMMM d, yyyy")}";

            foreach (var batch in recipients.Batch(SendGridService.BatchSize))
            {
                var subjects = Enumerable.Repeat(subject, batch.Count).ToList();

                var substitutions = Enumerable.Repeat(new Dictionary <string, string>
                {
                    { "{{print_url}}", pdfUrl }
                }, batch.Count).ToList();

                await _sendGridService.SendEmail(company.Id, batch, subjects, emailTemplate, emailTemplate, substitutions,
                                                 jumpStart.DateTime);

                foreach (var recipient in batch)
                {
                    recipient.Status = EmailStatus.Sent;
                }

                await _dbContext.SaveChangesAsync();
            }
        }
Example #3
0
        public async Task <byte[]> BuildScreenshotAsync(List <Post> posts)
        {
            await using var browser = await GetBrowser();

            await using var page = await browser.NewPageAsync();

            var emailTemplate = _jumpStartEmailTemplateService.GetEmailHtml(DateTime.UtcNow, posts);

            await page.SetContentAsync(emailTemplate);

            var screenShotData = await page.ScreenshotDataAsync(new ScreenshotOptions
            {
                FullPage = true
            });

            return(screenShotData);
        }
Example #4
0
        public async Task <byte[]> BuildScreenshotAsync(JumpStart jumpStart, List <Article> articles)
        {
            var emailTemplate = _jumpStartEmailTemplateService.GetEmailHtml(jumpStart, articles, null);

            await using var browser = await GetBrowser();

            await using var page = await browser.NewPageAsync();

            await page.SetContentAsync(emailTemplate);

            var screenShotData = await page.ScreenshotDataAsync(new ScreenshotOptions
            {
                FullPage = true
            });

            return(screenShotData);
        }