/// <summary> /// SendEmail method useful for get email and prepare email template to send to customer /// </summary> private void SendEmail() { tracingService.Trace("Entered EmailSender.SendEmail()"); try { templateName = EmailTemplateName.Get(executionContext); queryString = ToAddress.Get(executionContext); category = Category.Get(executionContext); tracingService.Trace("EmailSender.SendEmail(), Template Name:{0} InPutEmailString: {1}, Category: {2}", queryString, templateName, category); if (!string.IsNullOrEmpty(templateName) && !string.IsNullOrEmpty(queryString)) { EntityCollection emails = null; if (queryString.TrimStart().StartsWith("<")) { emails = GetEmailsByFetchXML(); } else { emails = GetEmailByString(); } if (null != emails && emails.Entities.Count > 0) { PrepareEmail(emails); } } } catch (Exception ex) { throw ex; } }
/// <inheritdoc /> public Task <EmailTemplate> UpdateAsync(EmailTemplateName templateName, EmailTemplateUpdateRequest request) { return(Connection.PutAsync <EmailTemplate>("email-templates/{templateName}", request, null, null, new Dictionary <string, string> { { "templateName", ToEnumString <EmailTemplateName>(templateName) } }, null, null)); }
public async Task <SendGridMessage> Build(EmailTemplateName template, Dictionary <string, string> items) { var sendGridMessage = new SendGridMessage(); EmailTemplate emailTemplate; switch (template) { case EmailTemplateName.BookingConfirmation: emailTemplate = await _context.EmailTemplates.SingleAsync(x => x.Name == nameof(EmailTemplateName.BookingConfirmation)); break; case EmailTemplateName.NewCustomer: emailTemplate = await _context.EmailTemplates.SingleAsync(x => x.Name == nameof(EmailTemplateName.NewCustomer)); break; default: throw new NotSupportedException(""); } string result = emailTemplate.Value; foreach (var item in items) { result = result.Replace(item.Key, item.Value); } sendGridMessage.HtmlContent = result; return(sendGridMessage); }
/// <inheritdoc /> public Task <EmailTemplate> PatchAsync(EmailTemplateName templateName, EmailTemplatePatchRequest request) { return(Connection.PatchAsync <EmailTemplate>("email-templates/{templateName}", request, new Dictionary <string, string> { { "templateName", ToEnumString <EmailTemplateName>(templateName) } })); }
/// <inheritdoc /> public Task <EmailTemplate> GetAsync(EmailTemplateName templateName) { return(Connection.GetAsync <EmailTemplate>("email-templates/{templateName}", new Dictionary <string, string> { { "templateName", ToEnumString <EmailTemplateName>(templateName) } }, null, null, null)); }
private async Task SendEmailAsync( EmailTemplateName template, int?opportunityId, int?opportunityItemId, string toAddress, IDictionary <string, string> tokens, string createdBy) { await _emailService.SendEmailAsync(template.ToString(), toAddress, opportunityId, opportunityItemId, tokens, createdBy); }
private async Task <string> GetEmailBody(EmailTemplateName emailTemplateName, EmailHistoryDto emailHistoryDto) { var emailBody = string.Empty; var emailBodyDto = await GetEmailBodyDto(emailTemplateName, emailHistoryDto); if (emailBodyDto != null) { emailBody = GetEmailBodyFrom(emailBodyDto); } return(emailBody); }
private async Task <EmailBodyDto> GetEmailBodyDto(EmailTemplateName emailTemplateName, EmailHistoryDto emailHistoryDto) { if (!emailHistoryDto.OpportunityId.HasValue) { return(null); } EmailBodyDto emailBodyDto = null; switch (emailTemplateName) { case EmailTemplateName.EmployerFeedback: case EmailTemplateName.EmployerFeedbackV2: case EmailTemplateName.EmployerReferral: case EmailTemplateName.EmployerReferralComplex: case EmailTemplateName.EmployerReferralV3: case EmailTemplateName.EmployerReferralV4: case EmailTemplateName.EmployerReferralV5: emailBodyDto = await _opportunityRepository.GetEmailDeliveryStatusForEmployerAsync( emailHistoryDto.OpportunityId.Value, emailHistoryDto.SentTo); break; case EmailTemplateName.ProviderFeedback: case EmailTemplateName.ProviderFeedbackV2: case EmailTemplateName.ProviderQuarterlyUpdate: case EmailTemplateName.ProviderReferral: case EmailTemplateName.ProviderReferralComplex: case EmailTemplateName.ProviderReferralV3: case EmailTemplateName.ProviderReferralV4: case EmailTemplateName.ProviderReferralV5: emailBodyDto = await _opportunityRepository.GetEmailDeliveryStatusForProviderAsync( emailHistoryDto.OpportunityId.Value, emailHistoryDto.SentTo); break; } return(emailBodyDto); }
public EmailTemplateDto GetByEmailTemplateName(EmailTemplateName name) { var emailTemplate = _emailTemplateRepository.GetByEmailTemplateName(name); return new EmailTemplateDtoMapper().Map(emailTemplate); }
public async Task SendProviderReferralEmailAsync(int opportunityId, IEnumerable <int> itemIds, int backgroundProcessHistoryId, string username) { if (await GetBackgroundProcessHistoryDataAsync(backgroundProcessHistoryId) == null) { await _functionLogRepository.CreateAsync(new FunctionLog { ErrorMessage = $"Background Processing History not found or not pending for id {backgroundProcessHistoryId} for provider referral emails", FunctionName = nameof(ReferralEmailService), RowNumber = -1 }); return; } var itemIdList = itemIds.ToList(); var referrals = await _opportunityRepository.GetProviderReferralsAsync(opportunityId, itemIdList); try { if (referrals == null || referrals.Count == 0) { await _functionLogRepository.CreateAsync(new FunctionLog { ErrorMessage = $"No provider referrals found for opportunity id {opportunityId} with {itemIdList.Count} items", FunctionName = nameof(ReferralEmailService), RowNumber = -1 }); } else { //Group by opportunity item, then loop over that with referrals onside var opportunityItemGroups = ( from p in referrals orderby p.OpportunityItemId group p by p.OpportunityItemId into g select new { OpportunityItemId = g.Key, Referrals = g.Select(c => c).ToList() } ).ToList(); foreach (var opportunityItem in opportunityItemGroups) { foreach (var referral in opportunityItem.Referrals) { var placements = GetNumberOfPlacements(referral.PlacementsKnown, referral.Placements); var tokens = new Dictionary <string, string> { { "contact_name", referral.ProviderPrimaryContact }, { "provider_name", referral.ProviderDisplayName }, { "route", referral.RouteName.ToLowerInvariant() }, { "venue_text", referral.VenueText }, { "search_radius", referral.DistanceFromEmployer }, { "job_role_list", string.IsNullOrEmpty(referral.JobRole) || referral.JobRole == "None given" ? $"* looking for students in courses related to {referral.RouteName.ToLowerInvariant()}" : $"* looking for this job role: {referral.JobRole}" }, { "employer_business_name", referral.CompanyName.ToTitleCase() }, { "employer_contact_name", referral.EmployerContact.ToTitleCase() }, { "employer_contact_number", referral.EmployerContactPhone }, { "employer_contact_email", referral.EmployerContactEmail }, { "employer_town_postcode", $"{referral.Town} {referral.Postcode}" }, { "number_of_placements", placements } }; const EmailTemplateName template = EmailTemplateName.ProviderReferralV5; await SendEmailAsync(template, opportunityId, referral.ProviderPrimaryContactEmail, tokens, referral.CreatedBy, referral.OpportunityItemId); if (!string.IsNullOrWhiteSpace(referral.ProviderSecondaryContactEmail) && !string.IsNullOrWhiteSpace(referral.ProviderSecondaryContact)) { tokens["contact_name"] = referral.ProviderSecondaryContact; await SendEmailAsync(template, opportunityId, referral.ProviderSecondaryContactEmail, tokens, referral.CreatedBy, referral.OpportunityItemId); } } await SetOpportunityItemsAsCompletedAsync(new[] { opportunityItem.OpportunityItemId }, username); } } await CompleteRemainingProvisionGapsAsync(opportunityId, username); await UpdateBackgroundProcessHistoryAsync(backgroundProcessHistoryId, referrals?.Count ?? 0, BackgroundProcessHistoryStatus.Complete, username); } catch (Exception ex) { var errorMessage = $"Error sending provider referral emails. {ex.Message} " + $"Opportunity id {opportunityId}" + $"\r\nInner exception: {ex.InnerException?.Message}\r\n" + $"Stack trace: {ex.StackTrace}"; await _functionLogRepository.CreateAsync(new FunctionLog { ErrorMessage = errorMessage, FunctionName = nameof(ReferralEmailService), RowNumber = -1 }); await UpdateBackgroundProcessHistoryAsync(backgroundProcessHistoryId, referrals?.Count ?? 0, BackgroundProcessHistoryStatus.Error, username, errorMessage); } }
/// <summary> /// Updates an email template. /// </summary> /// <param name="templateName">The name of the email template to patch.</param> /// <param name="request">The <see cref="EmailTemplateUpdateRequest"/> containing details of the template to update.</param> /// <returns>The newly updated <see cref="EmailTemplate"/>.</returns> public Task <EmailTemplate> UpdateAsync(EmailTemplateName templateName, EmailTemplateUpdateRequest request) { return(Connection.SendAsync <EmailTemplate>(HttpMethod.Put, BuildUri($"email-templates/{templateName.ToEnumString()}"), request, DefaultHeaders)); }
/// <summary> /// Updates an email template. /// </summary> /// <param name="templateName">The name of the email template to update.</param> /// <param name="request">The <see cref="EmailTemplatePatchRequest"/> containing details of the template to patch.</param> /// <returns>The newly updated <see cref="EmailTemplate"/>.</returns> public Task <EmailTemplate> PatchAsync(EmailTemplateName templateName, EmailTemplatePatchRequest request) { return(Connection.SendAsync <EmailTemplate>(new HttpMethod("PATCH"), BuildUri($"email-templates/{templateName.ToEnumString()}"), request, DefaultHeaders)); }
/// <summary> /// Gets an email template. /// </summary> /// <param name="templateName">The name of email template you wish to retrieve.</param> /// <returns>The <see cref="EmailTemplate"/> that was requested.</returns> public Task <EmailTemplate> GetAsync(EmailTemplateName templateName) { return(Connection.GetAsync <EmailTemplate>(BuildUri($"email-templates/{templateName.ToEnumString()}"), DefaultHeaders)); }