/// <summary> /// Performa a send mail /// </summary> /// <param name="request">Request data</param> /// <param name="cancellationToken">A System.Threading.CancellationToken to observe while waiting for the task to complete</param> private async Task <IActionResult> RunSendAsync(SendRequest request, CancellationToken cancellationToken = default) { string queryRedirect = HttpContext.Request.Query["redirect"]; EmailAddress redirect = null; if (!string.IsNullOrWhiteSpace(queryRedirect) && Regex.IsMatch(queryRedirect, @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$")) { redirect = new EmailAddress(queryRedirect); } Message message = request.Map(); (SendMailResult, Guid)result = await _mailService.SendMail(message, redirect); if (result.Item1.Success) { return(Ok(result.Item2)); } else { return(BadRequest(PrepareNotifications(result.Item1.Errors.ToDictionary(k => k.Key, v => v.Key)))); } }