Ejemplo n.º 1
0
        public async Task <MessageDispatchResult> SendAsync(IMessage message)
        {
            var mailMessage = EmailMessage.CreateFromMessage(message);

            var credentials = this.GetCredentials();

            var client = new AmazonSimpleEmailServiceClient(credentials);

            var request = new SendRawEmailRequest {
                RawMessage = new RawMessage {
                    Data = RawMailHelper.ConvertMailMessageToMemoryStream(mailMessage)
                }
            };

            var response = await client.SendRawEmailAsync(request);

            if (response.HttpStatusCode == HttpStatusCode.OK && !string.IsNullOrEmpty(response.MessageId))
            {
                return(new MessageDispatchResult {
                    Succeeded = true, MessageId = response.MessageId
                });
            }

            return(new MessageDispatchResult
            {
                Succeeded = false,
                MessageId = response.MessageId,
                Errors = $"{response.HttpStatusCode}: {StringifyMetaData(response.ResponseMetadata)}"
            });
        }