Exemplo n.º 1
0
 public void Deliver(MailMessage message, SendCompletedEventHandler sendCompleted = null, object userState = null)
 {
     _decorated.Deliver(message, GetOnSendCompleted(message, sendCompleted), new RetryUserState
     {
         UserState = userState,
         CountDown = 3,
     });
 }
Exemplo n.º 2
0
        public void Audit(Exception exception)
        {
            var error = new Error(exception);

            // first try to post it to the Elmah log
            try
            {
                var log = ErrorLog.GetDefault(HttpContext.Current);
                log.Log(error);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Failed to add exception to Elmah error logger: {0}", ex.Message), "Error");
            }

            // second try to send it via Elmah mail
            try
            {
                _mailMessageSender.Deliver(CreateMailMessage(exception));
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Failed to send Elmah exception email: {0}", ex.Message), "Error");
            }
        }
Exemplo n.º 3
0
        public void Deliver(int emailMessageId)
        {
            var entity = _entities.Query <EmailMessage>()
                         .EagerLoad(x => x.EmailAddress)
                         .ById(emailMessageId, false)
            ;

            // don't send the message if it has already been sent
            if (entity.SentOnUtc.HasValue)
            {
                return;
            }

            // don't sent the message if it is not supposed to be sent yet
            if (entity.SendOnUtc > DateTime.UtcNow)
            {
                return;
            }

            var from        = new MailAddress(entity.From);
            var to          = new MailAddress(entity.EmailAddress.Value);
            var mailMessage = new MailMessage(from, to)
            {
                Subject    = entity.Subject,
                Body       = entity.Body,
                IsBodyHtml = entity.IsBodyHtml,
            };

            var sendState = new SendEmailMessageState
            {
                EmailMessageId = emailMessageId,
            };

            _mail.Deliver(mailMessage, OnSendCompleted, sendState);
        }
Exemplo n.º 4
0
        public void Deliver(MailMessage message, SendCompletedEventHandler sendCompleted = null, object userState = null)
        {
            const string messageFormat =
                @"
***********************************************
* This message was intercepted before it was
* sent over the network. The intended
* recipients were:
* {0}
***********************************************
";
            var messageBuilder = new StringBuilder();

            messageBuilder.AppendLine("TO:");
            AppendIntendedRecipients(message.To, messageBuilder);

            if (message.CC.Any())
            {
                messageBuilder.AppendLine("* CC:");
                AppendIntendedRecipients(message.CC, messageBuilder);
            }

            if (message.Bcc.Any())
            {
                messageBuilder.AppendLine("* BCC:");
                AppendIntendedRecipients(message.Bcc, messageBuilder);
            }

            message.To.Clear();
            message.CC.Clear();
            message.Bcc.Clear();

            foreach (var interceptor in _appConfiguration.MailInterceptors)
            {
                message.To.Add(interceptor);
            }

            var formattedMessage = string.Format(messageFormat, messageBuilder.ToString().Trim());

            message.Body = string.Format("{0}{1}", formattedMessage, message.Body);

            _decorated.Deliver(message, sendCompleted, userState);
        }