public async Task <string> SendAsync(string configid, MessageNotification notification, List <GlobalMergeVar> mergeVars) { dynamic messageConfig = (notification.ConfigData.MessageTypeConfig as IEnumerable <dynamic>).First(d => d.MessageType == notification.MessageType); var config = await _configReader.GetMessageConfigAsync(configid); var mandrill = new MandrillMessage { key = config.MandrillKey, template_name = messageConfig.TemplateName.ToString(), template_content = new List <TemplateContent>() { new TemplateContent { name = "main", content = "messageConfig.MainContent" } }, message = new Message { from_email = messageConfig.FromEmail, subject = messageConfig.Subject, to = new List <To>() { new To() { email = notification.Recipient.Email, sendtype = "to" } }, auto_html = "true", inline_css = "true", global_merge_vars = mergeVars } }; var response = await "https://mandrillapp.com/api/1.0/messages/send-template.json".AllowAnyHttpStatus().PostJsonAsync(mandrill); var body = await response.Content.ReadAsStringAsync(); var fileName = Guid.NewGuid().ToString() + ".json"; await _blob.WriteBlockBlobFromStringBodyAsync("mandrillbody", fileName, JsonConvert.SerializeObject(mandrill, Formatting.Indented)); await _log.LogAsync(configid, "mandrill", body, fileName); return(body); }
public async Task Invoke(HttpContext context) { context.Response.ContentType = "application/json"; await _log.LogAsync("", "unhandled", context.Features.Get <IExceptionHandlerFeature>()?.Error.InnerException.ToString(), null); object getError(Exception ex) { if (ex == null) { return(null); } context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(new[] { new { ErrorCode = "UnhandledException", Message = ex.Message } }); } using (var writer = new StreamWriter(context.Response.Body)) { new JsonSerializer().Serialize(writer, getError(context.Features.Get <IExceptionHandlerFeature>()?.Error)); await writer.FlushAsync().ConfigureAwait(false); } }