Ejemplo n.º 1
0
        public void HandleMailError(SendableMail mail, MessageProcessor.ConnectorInfo info, SMTPStatusCode?status,
                                    Exception e)
        {
            var connector = info.Connector;

            if (status == SMTPStatusCode.NotAvailiable)
            {
                if (mail.RetryCount < connector.RetryCount)
                {
                    Logger.InfoFormat("Remote host was not availiable, retrying to send mail in {0} (try {1}/{2})",
                                      connector.RetryTime, mail.RetryCount + 1, connector.RetryCount + 1);
                    mail.RetryCount++;
                    lock (_mailQueue)
                    {
                        _mailQueue.Enqueue(mail, connector.RetryTime);
                    }
                }
                else
                {
                    Logger.InfoFormat("Remote host was not availiable, but retry count exceeded (try {0}/{0}).",
                                      connector.RetryCount + 1);
                }
            }

            if (e != null)
            {
                Logger.Error("An error occured while sending a mail:", e);
            }

            // TODO
        }
Ejemplo n.º 2
0
        public void Enqueue(MailMessage mail)
        {
            var from    = new MailAddress(mail.Sender);
            var to      = mail.Recipients.Select(r => new MailAddress(r)).ToArray();
            var content = new MailContent(mail.Subject, from, mail.Html, mail.Text);

            foreach (var recipient in to)
            {
                content.AddRecipient(recipient);
            }
            var parsed       = new Mail(from, to, content.ToString());
            var sendableMail = new SendableMail(parsed, mail.Connector);

            _mailQueue.Enqueue(sendableMail, TimeSpan.Zero);
        }