コード例 #1
0
        public void Save(QueuedMail mail)
        {
            if (mail.Id == default(int))
            {
                mail.Id = DateTime.UtcNow.Timestamp();
            }

            _repository.Save(mail);
        }
コード例 #2
0
        void processRetryMail(CancellationToken token)
        {
            if (_activeRetryCount > _maxParallelMessages)
            {
                return;
            }

            Interlocked.Increment(ref _activeRetryCount);
            QueuedMail msg = null;

            try {
                if (!token.IsCancellationRequested && _retryQueue.TryDequeue(out msg))
                {
                    if (++msg.RetryCount > _maxRetry)
                    {
                        _logger.Error("Sending mail '{0}' to {1}: maxretry has been exceeded {2}\r\nLast error is: {3}", msg.Msg.Subject, msg.Msg.Recipients, _maxRetry, msg.LastError.ToString());
                        msg.Msg.Dispose();
                    }
                    else
                    {
                        DateTime dt = DateTime.UtcNow;
                        using (ISmpClient cli = _clifac.Create())
                        {
                            cli.Send(msg.Msg);
                        }

                        if ((DateTime.UtcNow - dt).TotalSeconds > WarnTimeInSec)
                        {
                            _logger.Warn("Sending mail '{0}', to {1} took extratime: {2}s", msg.Msg.Subject, msg.Msg.Recipients, (DateTime.UtcNow - dt).TotalSeconds);
                        }

                        msg.Msg.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Exception(string.Format("On sending news, queue size = {0}", _retryQueue.Count), ex);
                if (!token.IsCancellationRequested)
                {
                    msg.LastError = ex;
                    _retryQueue.Enqueue(msg);
                }
            }
            finally {
                Interlocked.Decrement(ref _activeRetryCount);
            }

            if (_retryQueue.Count > 0 && !token.IsCancellationRequested)
            {
                startRetrying();
            }
        }
コード例 #3
0
        public static void Save(this IQueuedMailService service,
                                MailMessage message,
                                int accountConfigId)
        {
            var queuedMail = new QueuedMail {
                From     = message.From.Address,
                FromName = message.From.DisplayName,
                To       = message.To[0].Address,
                ToName   = message.To[0].DisplayName,
                Cc       = string.Join(";",
                                       message.CC),
                Bcc = string.Join(";",
                                  message.Bcc),
                Subject         = message.Subject,
                Body            = message.Body,
                IsBodyHtml      = message.IsBodyHtml,
                AccountConfigId = accountConfigId
            };

            service.Save(queuedMail);
        }