Example #1
0
        public SendGridMessage CreateSendGridMessage(EmailNotificationRequest notification)
        {
            var message         = base.Create(notification);
            var sendGridMessage = message.ConvertToSendGridMessage();

            return(sendGridMessage);
        }
Example #2
0
        public async Task <EmailNotificationResponse> SendAsync(EmailNotificationRequest request)
        {
            var message = _postmarkMessageFactory.Create(request);

            var response = await _postmarkClient.SendMessageAsync(message).ConfigureAwait(false);

            return(new EmailNotificationResponse
            {
                IsSent = response.Status == PostmarkStatus.Success,
                Message = response.ErrorCode.ToString(CultureInfo.InvariantCulture)
            });
        }
Example #3
0
        public EmailNotificationResponse Send(EmailNotificationRequest request)
        {
            var message = _postmarkMessageFactory.Create(request);

            var response = AsyncHelper.RunSync(() => _postmarkClient.SendMessageAsync(message));

            return(new EmailNotificationResponse
            {
                IsSent = response.Status == PostmarkStatus.Success,
                Message = response.ErrorCode.ToString(CultureInfo.InvariantCulture)
            });
        }
        private static SendEmailRequest CreateRequest(EmailNotificationRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request), "EmailNotificationRequest cannot be null");
            }

            if (request.To == null)
            {
                throw new ArgumentNullException(
                          $"{nameof(request)}.{nameof(request.To)}", "To email address cannot be null");
            }

            if (request.From == null)
            {
                throw new ArgumentNullException(
                          $"{nameof(request)}.{nameof(request.From)}", "From email address cannot be null");
            }

            var destination = new Destination();

            foreach (var mailAddress in request.To)
            {
                destination.ToAddresses.Add(mailAddress.Address);
            }

            foreach (var mailAddress in request.Cc)
            {
                destination.CcAddresses.Add(mailAddress.Address);
            }

            foreach (var mailAddress in request.Bcc)
            {
                destination.BccAddresses.Add(mailAddress.Address);
            }

            return(new SendEmailRequest
            {
                Destination = destination,
                ReplyToAddresses = new List <string> {
                    request.From.Address
                },
                Message = new Message(
                    new Content(request.Subject),
                    new Body(new Content(request.Body)))
            });
        }
Example #5
0
        public EmailNotificationResponse Send(EmailNotificationRequest request)
        {
            try
            {
                var mailGunRequest = _mailMessageFactory.Create(request);
                var response       = _mailGunClient.SendMail(mailGunRequest);

                return(new EmailNotificationResponse
                {
                    IsSent = true,
                    Message = response.Message
                });
            }
            catch (Exception ex)
            {
                Log.Error($"Email failed to: {request.To}. Subject: {request.Subject}.", ex);

                return(new EmailNotificationResponse
                {
                    Message = ex.Message
                });
            }
        }
        public async Task <EmailNotificationResponse> SendAsync(EmailNotificationRequest request)
        {
            try
            {
                var amazonRequest = CreateRequest(request);

                var response = await _simpleEmailServiceClient.SendEmailAsync(amazonRequest).ConfigureAwait(false);

                return(new EmailNotificationResponse
                {
                    IsSent = response.HttpStatusCode == HttpStatusCode.OK
                });
            }
            catch (Exception ex)
            {
                Log.Error($"Email failed to: {request.To}. Subject: {request.Subject}.", ex);

                return(new EmailNotificationResponse
                {
                    Message = ex.Message
                });
            }
        }
        public EmailNotificationResponse Send(EmailNotificationRequest request)
        {
            try
            {
                var amazonRequest = CreateRequest(request);

                var response = _simpleEmailServiceClient.SendEmail(amazonRequest);

                return(new EmailNotificationResponse
                {
                    IsSent = response.HttpStatusCode == HttpStatusCode.OK
                });
            }
            catch (Exception ex)
            {
                Log.Error($"Email failed to: {request.To}. Subject: {request.Subject}.", ex);

                return(new EmailNotificationResponse
                {
                    Message = ex.Message
                });
            }
        }
        public async Task <EmailNotificationResponse> SendAsync(EmailNotificationRequest request)
        {
            try
            {
                var message  = _mailMessageFactory.CreateSendGridMessage(request);
                var response = await _sendGridClient.SendEmailAsync(message);

                return(new EmailNotificationResponse
                {
                    IsSent = response.StatusCode == HttpStatusCode.Accepted,
                    Message = await response.Body.ReadAsStringAsync()
                });
            }
            catch (Exception ex)
            {
                Log.Error($"Email failed to: {request.To}. Subject: {request.Subject}.", ex);

                return(new EmailNotificationResponse
                {
                    Message = ex.Message
                });
            }
        }
 public PostmarkMessage Create(EmailNotificationRequest request)
 {
     return(_mailMessageFactory.Create(request).ToPostmarkMessage());
 }