public async Task SendUserRegistrationMessage(User user, string messageId) { var userAccessCode = GetUserAccessCode(user); var email = new Email { SystemId = Guid.NewGuid().ToString(), TemplateId = "UserRegistration", RecipientsAddress = user.Email, ReplyToAddress = ReplyToAddress, Subject = "Access your apprenticeship levy account", Tokens = new Dictionary <string, string> { { "FirstName", user.FirstName }, { "AccessCode", userAccessCode.Code }, { "CodeExpiry", userAccessCode.ExpiryTime.ToString("d MMMM yyyy") }, { "ReturnUrl", userAccessCode.ReturnUrl } } }; try { await _notificationsApi.SendEmail(email); } catch (Exception ex) { _logger.Error(ex, "SendUserRegistrationMessage: Error while sending email"); } }
private async Task SendEmails(IEnumerable <Email> emails, string jobId) { var emailsToSendCount = emails?.Count(); if (emails == null || emailsToSendCount == 0) { _logger.Debug($"No emails to send, JobId: {jobId}"); return; } if (!_config.SendEmail) { _logger.Info($"Sending emails is turned off, JobId {jobId}"); return; } var stopwatch = Stopwatch.StartNew(); _logger.Debug($"About to send {emailsToSendCount} emails, JobId: {jobId}"); var tasks = emails.Select(email => _notificationsApi.SendEmail(email)); await Task.WhenAll(tasks); _logger.Debug($"Took {stopwatch.ElapsedMilliseconds} milliseconds to send {emailsToSendCount} emails, JobId; {jobId}", new Dictionary <string, object> { { "emailCount", emailsToSendCount }, { "duration", stopwatch.ElapsedMilliseconds }, { "JobId", jobId } }); }
protected override async Task HandleCore(UnsubscribeNotificationCommand command) { _validator.Validate(command); var settings = await _accountRepository.GetUserAccountSettings(command.UserRef); var setting = settings.SingleOrDefault(m => m.AccountId == command.AccountId); if (setting == null) { throw new Exception($"Missing settings for account {command.AccountId} and user with ref {command.UserRef}"); } if (!setting.ReceiveNotifications) { throw new Exception($"Trying to unsubscribe from an already unsubscribed account, {command.AccountId}"); } setting.ReceiveNotifications = false; await _accountRepository.UpdateUserAccountSettings(command.UserRef, settings); try { var user = _userRepository.GetUserByRef(command.UserRef); await Task.WhenAll(user); _logger.Info($"Sending email to unsubscriber: {user.Result.Id}"); var email = CreateEmail(user.Result, setting.Name, command.NotificationSettingUrl); await _notificationsApi.SendEmail(email); } catch (Exception ex) { _logger.Error(ex, "Error sending email to notifications api"); throw; } }
public async Task Send(IEnumerable <CertificateResponse> certificateResponses) { var emailTemplate = await _assessorServiceApi.GetEmailTemplate(EMailTemplateNames.PrivatelyFundedCertificatesApprovals); var personalisation = CreatePersonalisationTokens(certificateResponses); _aggregateLogger.LogInfo("Send Email"); var recipients = emailTemplate.Recipients.Split(';').Select(x => x.Trim()); foreach (var recipient in recipients) { var email = new Email { RecipientsAddress = recipient, TemplateId = emailTemplate.TemplateId, ReplyToAddress = "*****@*****.**", Subject = "Test Subject", SystemId = "PrivatelyFundedCertificatesApprovals", Tokens = personalisation }; await _notificationsApi.SendEmail(email); } }
public async Task Send(int batchNumber, List <CertificateResponse> certificateResponses, string certificatesFileName) { var emailTemplate = await _assessorServiceApi.GetEmailTemplate(EMailTemplateNames.PrintAssessorCoverLetters); var personalisation = CreatePersonalisationTokens(certificateResponses, certificatesFileName); _aggregateLogger.LogInfo("Send Email"); var recipients = emailTemplate.Recipients.Split(';').Select(x => x.Trim()); foreach (var recipient in recipients) { var email = new Email { RecipientsAddress = recipient, TemplateId = emailTemplate.TemplateId, ReplyToAddress = "*****@*****.**", Subject = "Test Subject", SystemId = "PrintAssessorCoverLetters", Tokens = personalisation }; await _notificationsApi.SendEmail(email); } }
private async Task SendEmailViaNotificationsApi(EmailTemplate emailTemplate, string toAddress, string replyToAddress, string subject, Dictionary <string, string> personalisationTokens) { if (emailTemplate is null) { return; } try { // Note: If anything is hard copied in the template then it will ignore the respected value(s) below var email = new Notifications.Api.Types.Email { RecipientsAddress = toAddress, TemplateId = emailTemplate.TemplateId, ReplyToAddress = replyToAddress ?? REPLY_TO_ADDRESS, SystemId = SYSTEM_ID, Subject = subject ?? SUBJECT, Tokens = personalisationTokens }; _logger.LogInformation($"Sending {emailTemplate.TemplateName} email ({emailTemplate.TemplateId}) to: '{toAddress}'"); await _notificationsApi.SendEmail(email); } catch (Exception ex) { _logger.LogError(ex, $"Error sending {emailTemplate.TemplateName} email ({emailTemplate.TemplateId}) to: '{toAddress}'"); } }
private async Task SendEmail(string sendToAddress, Email email) { try { _logger.LogInformation($"Sending email to {sendToAddress}"); await _emailService.SendEmail(email); } catch (HttpRequestException ex) { _logger.LogError(ex, $"Unable to send email for user: {sendToAddress}"); throw; } }
public Task SendEmail(Email email) { _logger.Debug($"Sending email to [{email.RecipientsAddress}] in a background task."); HostingEnvironment.QueueBackgroundWorkItem(async cancellationToken => { try { await _notificationsApi.SendEmail(email); } catch (Exception ex) { _logger.Error(ex, $"Error using the Notification Api when trying to send email {email.RecipientsAddress}."); } }); return(Task.CompletedTask); }
protected override async Task HandleCore(SendNotificationCommand message) { var validationResult = _validator.Validate(message); if (!validationResult.IsValid()) { _logger.Info("SendNotificationCommandHandler Invalid Request"); throw new InvalidRequestException(validationResult.ValidationDictionary); } try { await _notificationsApi.SendEmail(message.Email); } catch (Exception ex) { _logger.Error(ex, "Error sending email to notifications api"); } }
public async Task Send() { var personalisation = new Dictionary <string, string> { { "name", "john coxhead" }, { "day ", "1" }, { "day of week", "Monday" }, { "colour", "blue" } }; var email = new Email { RecipientsAddress = _webConfiguration.EmailTemplateSettings.RecipientsAddress, TemplateId = _webConfiguration.EmailTemplateSettings.TemplateId, ReplyToAddress = _webConfiguration.EmailTemplateSettings.ReplyToAddress, Subject = _webConfiguration.EmailTemplateSettings.Subject, SystemId = _webConfiguration.EmailTemplateSettings.SystemId, Tokens = personalisation }; await _notificationsApi.SendEmail(email); }
protected override async Task HandleCore(SendNotificationCommand message) { var validationResult = _validator.Validate(message); if (!validationResult.IsValid()) { _logger.Info("SendNotificationCommandHandler Invalid Request"); throw new InvalidRequestException(validationResult.ValidationDictionary); } try { //_logger.Info($"---- === ||| --> {message.Email.RecipientsAddress} <-- ||| === ----"); await _notificationsApi.SendEmail(message.Email); } catch (Exception ex) { _logger.Error(ex); } }
public async Task Handle(ApprovedTransferConnectionRequestEvent message, IMessageHandlerContext context) { var users = await _db.Value.Users.WhereReceiveNotifications(message.SenderAccountId).ToListAsync(); if (!users.Any()) { _logger.Info($"There are no users that receive notifications for SenderAccountId '{message.SenderAccountId}'"); } foreach (var user in users) { try { var email = new Email { RecipientsAddress = user.Email, TemplateId = "TransferConnectionRequestApproved", ReplyToAddress = "*****@*****.**", Subject = "x", SystemId = "x", Tokens = new Dictionary <string, string> { { "name", user.FirstName }, { "account_name", message.ReceiverAccountName }, { "link_notification_page", $"{_config.DashboardUrl}{string.Format(UrlFormat, message.SenderAccountHashedId)}" } } }; await _notificationsApi.SendEmail(email); } catch (Exception ex) { _logger.Error(ex, $"Unable to send approved transfer request notification to UserId '{user.Id}' for SenderAccountId '{message.SenderAccountId}'"); } } }
public async Task SendEmail(CommunicationMessage request) { _logger.LogInformation($"Trying to send message of type {request.RequestType} to {request.Recipient.Email}"); var email = new Email { TemplateId = request.TemplateId, RecipientsAddress = request.Recipient.Email, Tokens = request.DataItems.ToDictionary(x => x.Key, x => x.Value), SystemId = NotifySystemId, // any value is acceptable // following are overwritten in the service but required to be populated ReplyToAddress = "*****@*****.**", Subject = "This will be replaced by the template on Gov Notify" }; email.Tokens.Add(UserNameTokenKey, request.Recipient.Name); await _retryPolicy.ExecuteAsync(context => _dasNotifyClient.SendEmail(email), new Context(nameof(SendEmail))); _logger.LogInformation($"Successfully sent message of type {request.RequestType} to {request.Recipient.Email}"); }
private async Task SendEmailViaNotificationsApi(string toAddress, string templateId, Dictionary <string, string> personalisationTokens, string replyToAddress) { // Note: It appears that if anything is hard copied in the template it'll ignore any values below var email = new SFA.DAS.Notifications.Api.Types.Email { RecipientsAddress = toAddress, TemplateId = templateId, ReplyToAddress = replyToAddress, Subject = SUBJECT, SystemId = SYSTEM_ID, Tokens = personalisationTokens }; try { await _notificationsApi.SendEmail(email); } catch (Exception ex) { _logger.LogError(ex, $"Error sending email template {templateId} to {toAddress}"); } }
private async Task SendEmailViaNotificationsApi(string toAddress, string templateId, string templateName, Dictionary <string, string> personalisationTokens) { // Note: It appears that if anything is hard copied in the template it'll ignore any values below var email = new Email { RecipientsAddress = toAddress, TemplateId = templateId, ReplyToAddress = ReplyToAddress, Subject = Subject, SystemId = SystemId, Tokens = personalisationTokens }; try { _logger.LogInformation($"Sending {templateName} email ({templateId}) to {toAddress}"); await Task.Run(() => _notificationsApi.SendEmail(email)); } catch (Exception ex) { _logger.LogError(ex, $"Error sending {templateName} email ({templateId}) to {toAddress}"); } }