public void SendMail(ApplicationContext app, CreateEventSourceCommand commandEvent) { string bodyMessage = $"A aplicação {app.ApplicationName} parou de funcionar às {app.EventDateTime} " + ", email enviado automaticamente."; string emailMessage = $"OESP {app.ApplicationName}"; var command = new SendEmailCommand(emailAddress: EmailConfig.EmailAddress , emailOrigin: EmailConfig.EmailOrigin, message: emailMessage, body: bodyMessage); using (var scope = this.ServiceProvider.CreateScope()) { _sendEmail = scope.ServiceProvider.GetRequiredService <SendEmailHandler>(); var result = (CommandResult)_sendEmail.Handle(command); if (result.Ok) { InsertEmailEventSource(app, command, true); } else { InsertEmailEventSource(app, command, false); } } }
public void BulkTask() { var sw = new Stopwatch(); sw.Start(); const int count = 20; var tasks = new Task <SendEmailResponse> [count]; for (int i = 0; i < count; i++) { var cmd = new SendEmailCommand { Source = Helper.GetSenderEmailAddress(), }; cmd.Message.Subject.Data = "testing SES"; cmd.Message.Body.Html.Data = "<b>this is bold text</b>"; cmd.Message.Body.Text.Data = "this is not bold text"; cmd.Destination.ToAddresses.Add(Helper.GetRecipientEmailAddress()); var cp = new CommandProcessor(_builder); tasks[i] = cp.CreateTask(cmd, new SendEmailResponseParser()); } Task.WaitAll(tasks); sw.Stop(); Console.WriteLine(sw.Elapsed); }
protected override void Send(ILogger logger, Notification notification, AccountDbContext accountDbContext, string accountName, Guid accountId) { var to = notification.Address; var componentRepository = accountDbContext.GetComponentRepository(); var component = componentRepository.GetById(notification.Event.OwnerId); var path = ComponentHelper.GetComponentPathText(component); var subject = string.Format("{0} - {1}", path, GetEventImportanceText(notification.Event.Importance)); if (notification.Reason == NotificationReason.Reminder) { subject = subject + " (напоминание)"; } // составляем тело письма var user = accountDbContext.GetUserRepository().GetById(notification.UserId); var htmlBody = GetStatusEventHtml(user, logger, notification, component, accountDbContext, accountName); // сохраняем письмо в очередь var emailRepository = accountDbContext.GetSendEmailCommandRepository(); var command = new SendEmailCommand() { Id = Guid.NewGuid(), Body = htmlBody, IsHtml = true, Subject = subject, To = to, ReferenceId = notification.Id }; emailRepository.Add(command); }
public async Task <IActionResult> ContactUs(string contactName, string emailAddress) { // send Thankyou email to contact var thankYouEmail = new SendEmailCommand() { To = emailAddress, Subject = "Thank you for reaching out", Body = "we will contact you shortly" }; await _queueCommunicator.SendAsync(thankYouEmail); // send new contact email to admin var adminEmailCommand = new SendEmailCommand() { To = "*****@*****.**", Subject = "New Contact", Body = $"{contactName} has reached out via contact form. Please respond back at {emailAddress}" }; await _queueCommunicator.SendAsync(adminEmailCommand); ViewBag.Message = "Thank you we've recived your message =)"; return(View()); }
public void Bulk() { var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 10; i++) { var cmd = new SendEmailCommand { Source = Helper.GetSenderEmailAddress(), }; cmd.Message.Subject.Data = "testing SES"; cmd.Message.Body.Html.Data = "<b>this is bold text</b>"; cmd.Message.Body.Text.Data = "this is not bold text"; cmd.Destination.ToAddresses.Add(Helper.GetRecipientEmailAddress()); var cp = new CommandProcessor(_builder); SendEmailResponse response = cp.Process(cmd, new SendEmailResponseParser()); Console.WriteLine(response.Command + " : ID " + response.RequestID); Console.WriteLine(response.Command + " : MessageID " + response.MessageID); } sw.Stop(); Console.WriteLine(sw.Elapsed); }
public void ThenInvalidCommandFailsValidation() { var cmd = new SendEmailCommand(); var expectedException = Assert.ThrowsAsync <CustomValidationException>(async() => await _commandHandler.Handle(cmd)); Assert.That(expectedException.ValidationResult.IsValid, Is.False); }
public async Task <IActionResult> SEND_EMAIL([FromBody] SendEmailCommand command) { var response = await _mediator.Send(command); if (response.Status.IsSuccessful) { return(Ok(response)); } return(BadRequest(response)); }
public async Task Handle(ReservationCreatedEvent @event) { var command = new SendEmailCommand(new Reservation { Recipent = await _userRepository.GetById(@event.UserId), Resource = await _resourceRepository.GetById(@event.ResourceId), Timeslot = @event.Timeslot }, Template.BookingConfirmation); await _eventBus.SendCommand(command); }
public async Task <IActionResult> PostEmail([FromBody] SendEmailRequest request, CancellationToken cancellationToken) { Logger.LogInformation(JsonConvert.SerializeObject(request)); SendEmailCommand command = SendEmailCommand.Create(request); await this.CommandRouter.Route(command, cancellationToken); return(this.Ok(command.Response)); }
public void ValidateOk() { var command = new SendEmailCommand(emailAddress: "*****@*****.**", emailOrigin: "*****@*****.**" , message: "mensagem", body: "corpo"); var handle = new SendEmailHandler(_service); var result = (CommandResult)handle.Handle(command); Assert.AreEqual(true, result.Ok); }
public void ValidateFail() { var command = new SendEmailCommand(emailAddress: "email", emailOrigin: "email" , message: "", body: ""); var handle = new SendEmailHandler(_service); var result = (CommandResult)handle.Handle(command); Assert.AreEqual(false, result.Ok); }
public async Task Handle(SendEmailCommand command) { var notification = new PendingNotification(command.Id, command.To, command.Subject, command.Body); var content = JsonConvert.SerializeObject(notification); await _httpClient.PostAsync(_notificationsApiSettings.Path, new StringContent(content, Encoding.UTF8, "application/json")); }
public void LeavesEmailInDropFolder() { var vModel = new SendEmailModel {Body = "", ToAddress = "*****@*****.**", Subject = "test"}; var vCommand = new SendEmailCommand(vModel); vCommand.Execute(); }