private static void UnmarshallResult(XmlUnmarshallerContext context, SendBulkTemplatedEmailResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("Status/member", targetDepth)) { var unmarshaller = BulkEmailDestinationStatusUnmarshaller.Instance; var item = unmarshaller.Unmarshall(context); response.Status.Add(item); continue; } } } return; }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { SendBulkTemplatedEmailResponse response = new SendBulkTemplatedEmailResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.IsStartElement) { if (context.TestExpression("SendBulkTemplatedEmailResult", 2)) { UnmarshallResult(context, response); continue; } if (context.TestExpression("ResponseMetadata", 2)) { response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context); } } } return(response); }
private string SendTemplatedEmailInternal(List <EmailTempalteData> emailTempalteData, string templateId, string defaultTemplateDataAsJson) { using (AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(RegionEndpoint)) { SendBulkTemplatedEmailRequest sendBulkTemplatedEmailRequest = new SendBulkTemplatedEmailRequest { Source = FromEmailAddress, Template = templateId, Destinations = emailTempalteData .Select(x => new BulkEmailDestination { Destination = new Destination(x.ToEmailAdresses), ReplacementTemplateData = x.ReplacementTemplateDataAsJson }) .ToList(), DefaultTemplateData = defaultTemplateDataAsJson, ConfigurationSetName = ConfigurationSetName }; try { _logger.LogInformation("Sending email using Amazon SES..."); SendBulkTemplatedEmailResponse response = client.SendBulkTemplatedEmailAsync(sendBulkTemplatedEmailRequest).Result; _logger.LogInformation($"HttpStatusCode = {response.HttpStatusCode}, MessageId = {string.Join(",", response.Status.Select(x => $"{x.MessageId}|{x.Status}").ToArray())}, RequestId = {response.ResponseMetadata.RequestId}, Metadata = {string.Join("; ", response.ResponseMetadata.Metadata)}"); _logger.LogInformation("The email was sent successfully."); return(string.Join(",", response.Status.Select(x => $"{x.MessageId}|{x.Status}").ToArray())); } catch (Exception ex) { _logger.LogError("The email was not sent."); _logger.LogError("Error message: " + ex.Message); throw ex; } } }