Example #1
0
 private void QueueAndJob_MailError(object sender, MailErrorEventArgs e)
 {
     if (_mailEventReceiver != null)
     {
         _mailEventReceiver.OnMailError(sender, e);
     }
 }
Example #2
0
 public virtual void OnMailError(object sender, MailErrorEventArgs e)
 {
     if (MailError != null)
     {
         MailError(this, e);
     }
 }
Example #3
0
        public void Delete(Guid mailID)
        {
            //process deleteing event
            MailDeletingMailEventArgs deletingArgs = new MailDeletingMailEventArgs();

            deletingArgs.EmailID = mailID;
            deletingArgs.Cancel  = false;
            OnDeletingMail(this, deletingArgs);

            try
            {
                MailQueueDB.DeleteMailFromQueue(this._connectionString, mailID);
            }
            catch (SqlException ex)
            {
                //Process Mail Error Event
                MailErrorEventArgs errorArgs = new MailErrorEventArgs();
                errorArgs.Exception = ex;
                errorArgs.ErrorType = MailErrorType.Delete;
                OnMailError(this, errorArgs);
            }

            //process deleted event
            MailDeletedMailEventArgs deletedArgs = new MailDeletedMailEventArgs();

            OnDeletedMail(this, deletedArgs);
        }
Example #4
0
        /// <summary>
        /// Add the email to the queue
        /// </summary>
        /// <param name="mail"></param>
        /// <remarks></remarks>
        public bool Enqueue(Email mail, ref string msg)
        {
            if (this._queueSize > this._count)
            {
                try
                {
                    //process adding mail event
                    MailAddingMailEventArgs addingMailArgs = new MailAddingMailEventArgs();
                    addingMailArgs.Email = mail;
                    OnAddingMail(this, addingMailArgs);

                    this._count = MailQueueDB.SaveMailToQueue(this._connectionString, mail);

                    //process added mail event
                    MailAddedMailEventArgs addedMailArgs = new MailAddedMailEventArgs();
                    addedMailArgs.Email = mail;
                    OnAddedMail(this, addedMailArgs);
                }
                catch (SqlException ex)
                {
                    msg = ex.Message;
                    //Process Mail Error Event
                    MailErrorEventArgs args = new MailErrorEventArgs();
                    args.Exception = ex;
                    args.ErrorType = MailErrorType.Enqueue;
                    OnMailError(this, args);

                    return(false);
                }
                return(true);
            }
            else
            {
                //process Exceed Queue Max Size event
                MailExceedQueueSizeEventArgs args = new MailExceedQueueSizeEventArgs();
                args.QueueMaxSize = this._queueSize;
                OnExceedQueueSize(this, args);
                msg = "Mail Queue is full, please try later.";
                return(false);
            }
        }
Example #5
0
        /// <summary>
        /// Get an email from the queue
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public List <Email> Dequeue()
        {
            List <Email> mailList = new List <Email>();

            try
            {
                mailList = MailQueueDB.GetMailsFromQueue(this._connectionString);
            }
            catch (SqlException ex)
            {
                //Process Mail Error event
                MailErrorEventArgs errorArgs = new MailErrorEventArgs();
                errorArgs.Exception = ex;
                errorArgs.ErrorType = MailErrorType.Dequeue;
                OnMailError(this, errorArgs);
            }

            MailDequeueMailEventArgs args = new MailDequeueMailEventArgs();

            args.EmailList = mailList;
            //Process the Dequeue Mail event
            OnDequeueMail(this, args);
            return(mailList);
        }
Example #6
0
        public void Run()
        {
            List <Email> mailList = new List <Email>();

            mailList = _queue.Dequeue();


            if (mailList != null)
            {
                foreach (Email mail in mailList)
                {
                    //Send mail

                    try
                    {
                        //process the Sending Mail event
                        MailSendingMailEventArgs sendingArgs = new MailSendingMailEventArgs();
                        sendingArgs.Email  = mail;
                        sendingArgs.Cancel = false;
                        OnSendingMail(this, sendingArgs);

                        if (sendingArgs.Cancel == false)
                        {
                            smtp.Send(mail);
                            //process the SendedMail event
                            MailSendedMailEventArgs sendedArgs = new MailSendedMailEventArgs();
                            //sendedArgs.Email = mail
                            OnSendedMail(this, sendedArgs);
                        }
                        _queue.Delete(mail.MailId);
                    }
                    catch (SmtpFailedRecipientsException ex)
                    {
                        //added by linxu on 208-7-28
                        _queue.UpdateFailure(mail.MailId, FailureInterval, NumberOfTries, IsArchiveFailure);
                        //Send Mail Error Event
                        MailErrorEventArgs args = new MailErrorEventArgs();
                        args.ErrorType = MailErrorType.SendMail;
                        args.Exception = ex;
                        OnMailError(this, args);
                    }
                    catch (SmtpException ex)
                    {
                        //Send failed
                        _queue.UpdateFailure(mail.MailId, FailureInterval, NumberOfTries, IsArchiveFailure);
                        //Send Mail Error Event
                        MailErrorEventArgs args = new MailErrorEventArgs();
                        args.ErrorType = MailErrorType.SendMail;
                        args.Exception = ex;
                        OnMailError(this, args);
                    }
                    catch (ArgumentNullException ex)
                    {
                        //added by linxu on 208-7-28
                        _queue.UpdateFailure(mail.MailId, FailureInterval, NumberOfTries, IsArchiveFailure);
                        //Send Mail Error Event
                        MailErrorEventArgs args = new MailErrorEventArgs();
                        args.ErrorType = MailErrorType.SendMail;
                        args.Exception = ex;
                        OnMailError(this, args);
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        //added by linxu on 208-7-28
                        _queue.UpdateFailure(mail.MailId, FailureInterval, NumberOfTries, IsArchiveFailure);
                        //Send Mail Error Event
                        MailErrorEventArgs args = new MailErrorEventArgs();
                        args.ErrorType = MailErrorType.SendMail;
                        args.Exception = ex;
                        OnMailError(this, args);
                    }
                }
            }
        }