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

            var pdfUrl = await _jumpStartPdfJob.CreatePdfUrlAsync(jumpStart);

            var emailTemplate = _jumpStartEmailTemplateService.GetEmailHtml(jumpStart.DateTime.Date, articles, pdfUrl);

            var recipients = await GetRecipients(jumpStart.Id);

            var subject = $"Project Blue Delta - {jumpStart.DateTime:MMMM d, yyyy}";

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

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

                await _dbContext.SaveChangesAsync();
            }
        }
Example #2
0
        private async Task <EmailInfo> GetEmailInfoAsync(JumpStart jumpStart, List <Data.Entity.Models.Email> emails, List <Article> articles)
        {
            var company = await _dbContext.Companies.FirstOrDefaultAsync(item => item.Name == VolkswagenCompany.Slug);

            var pdfUrl = await _jumpStartPdfJob.CreatePdfUrlAsync(jumpStart);

            var emailTemplate = _jumpStartEmailTemplateService.GetEmailHtml(jumpStart.DateTime.Date, articles, pdfUrl);

            return(new EmailInfo(company.Id, emails)
            {
                Subject = $"Project Blue Delta - {jumpStart.DateTime:MMMM d, yyyy}",
                HtmlContent = emailTemplate,
                PlainTextContent = emailTemplate,
                SendAt = jumpStart.DateTime
            });
        }