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 SendAsync(int memoId)
        {
            var memo = await _dbContext.Memos.FirstOrDefaultAsync(item => item.Id == memoId);

            var company = await _dbContext.Companies.FirstOrDefaultAsync(item => item.Name == VolkswagenCompany.Name);

            var templateData = new Dictionary <string, object>
            {
                { "subject", memo.Subject },
                { "date", memo.Date },
                { "to", memo.To },
                // To handle new lines correctly we are replacing them with <br> and use {{{description}}}
                // so we have to html encode here
                { "description", Regex.Replace(HttpUtility.HtmlEncode(memo.Description), @"\r\n?|\n", "<br>") }
            };

            var recipients = await _dbContext.EmailRecipients
                             .Where(item => item.MemoId == memoId && item.Status == EmailStatus.ReadyToSend)
                             .ToListAsync();

            foreach (var batch in recipients.Batch(SendGridService.BatchSize))
            {
                await _sendGridService.SendEmail(company.Id, recipients, templateData, nameof(EmailRecipient.MemoId),
                                                 memo.Id.ToString());

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

                await _dbContext.SaveChangesAsync();
            }
        }
Example #4
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();
            }
        }
        private bool SendApplicationToDatabase(ApplyViewModel applyViewModel)
        {
            if (applyViewModel.ApplicationId > 0)
            {
                var application = _applicationData.FindById(applyViewModel.ApplicationId);
                if (application == null)
                {
                    return(false);
                }
                application.Name  = applyViewModel.Name;
                application.Phone = applyViewModel.Phone;
                application.CommunicationEmail = applyViewModel.CommunicationEmail;
                application.Info   = applyViewModel.Info;
                application.CvFile = applyViewModel.CvFile;

                _applicationData.Update(application);
            }
            else
            {
                var jobOffer = _jobOfferData.FindById(applyViewModel.JobOfferId);
                if (jobOffer == null)
                {
                    return(false);
                }
                var application = new Application();
                application.UserEmail          = User.FindFirst("emails").Value;
                application.ApplicationId      = 0;
                application.JobOfferId         = applyViewModel.JobOfferId;
                application.OfferName          = jobOffer.Name;
                application.Name               = applyViewModel.Name;
                application.Phone              = applyViewModel.Phone;
                application.CommunicationEmail = applyViewModel.CommunicationEmail;
                application.Info               = applyViewModel.Info;
                application.CvFile             = applyViewModel.CvFile;
                _applicationData.Add(application);

                var hrEmail = _jobOfferData.GetHrEmail(applyViewModel.JobOfferId);

                if (hrEmail != null)
                {
                    var apikey = _configuration["sendgridapikey"];
                    SendGridService.SendEmail(hrEmail, applyViewModel.OfferName, apikey, application.CvFile);
                }
            }

            _applicationData.Commit();
            return(true);
        }
Example #6
0
        public async Task SendEmail(int tenantId, List <string> orders, decimal subTotal, decimal deliveryFee,
                                    decimal amount, decimal tax, DateTime deliveryDateTime, int userTimeZoneOffset, string paymentMethod,
                                    string?message, string userId)
        {
            var user = await _userManager.FindByIdAsync(userId);

            var tenant = await _meredithDbContext.Tenants
                         .Include(item => item.User)
                         .Include(item => item.Company)
                         .FirstOrDefaultAsync(item => item.Id == tenantId);

            var recipients = new List <Tuple <string, string?> >
            {
                Tuple.Create(user.Email, user.Name),
                Tuple.Create(tenant.User.Email, tenant.User.Name)
            };

            var templateData = new
            {
                subject = $"your order with {tenant.Company.Name}",
                tenant  = new
                {
                    h2    = tenant.Name,
                    phone = tenant.User.PhoneNumber,
                    email = tenant.User.Email
                },
                orderProducts   = string.Join("<br />", orders),
                subTotal        = subTotal,
                deliveryFee     = deliveryFee,
                amount          = amount,
                tax             = tax,
                deliveryAddress = user.Address,
                name            = user.Name,
                phone           = user.PhoneNumber,
                email           = user.Email,
                paymentMethod   = paymentMethod,
                deliveryTime    = deliveryDateTime.InZone(userTimeZoneOffset, "ddd, d MMM hh:mm"),
                message         = message ?? string.Empty,
                googleMaps      = user.GoogleLocation
            };

            await _sendGridService.SendEmail(tenant.Company.Id, recipients, templateData);
        }
Example #7
0
 public async Task SendGridServiceThrowsExceptionWhenWrongApiKeyIsUsed()
 {
     await Assert.ThrowsAsync <Exception>(() =>
                                          SendGridService.SendEmail("*****@*****.**", "testoffer", "badkey"));
 }