Ejemplo n.º 1
0
        /// <summary>
        /// Sends the specified email.
        /// </summary>
        /// <param name="emailMsg">Email message object.</param>
        /// <param name="resendOnError">If true, email manager will attempt to resend a message that fails due to an SMTP error.</param>
        /// <returns>True if email sent successfully; otherwise false if an error occurred and email was not sent.</returns>
        /// <remarks>Email manager will retry up to MaxNumResendAttempts times.</remarks>
        public stEmailSendResult SendEmail(PFEmailMessage emailMsg, bool resendOnError)
        {
            stEmailSendResult result = new stEmailSendResult(enEmailSendResult.Unknown, enEmailFailedReason.Unknown);
            bool queueForResend      = false;

            try
            {
                emailMsg.Send();
                result.emailSendResult   = enEmailSendResult.Success;
                result.emailFailedReason = enEmailFailedReason.NoError;
                result.failureMessages   = string.Empty;
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Attempt to send email to ");
                _msg.Append(emailMsg.ToAddress);
                _msg.Append(" failed. Error Message: ");
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                result.emailSendResult = enEmailSendResult.Failed;
                result.failureMessages = _msg.ToString();
                if (ex is SmtpException)
                {
                    result.emailFailedReason = enEmailFailedReason.SmtpException;
                    queueForResend           = true;
                }
                else if (ex is SmtpFailedRecipientException)
                {
                    result.emailFailedReason = enEmailFailedReason.SmtpRecipientsException;
                    queueForResend           = true;
                }
                else if (ex is InvalidOperationException)
                {
                    result.emailFailedReason = enEmailFailedReason.InvalidOperationsException;
                }
                else if (ex is ArgumentNullException)
                {
                    result.emailFailedReason = enEmailFailedReason.ArgumentNullException;
                }
                else
                {
                    result.emailFailedReason = enEmailFailedReason.GeneralError;
                }
            }
            finally
            {
                if (queueForResend && resendOnError)
                {
                    stEmailArchiveEntry newEntry = new stEmailArchiveEntry(result, emailMsg);
                    newEntry.firstSendAttempt = DateTime.Now;
                    newEntry.lastSendAttempt  = DateTime.Now;
                    _emailResendQueue.Add(newEntry);
                    _emailResendQueue.SaveToXmlFile(_emailResendQueueFile);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        //methods


        /// <summary>
        /// Sends the specified email.
        /// </summary>
        /// <param name="emailMsg">Email message object.</param>
        /// <returns>True if email sent successfully; otherwise false if an error occurred and email was not sent.</returns>
        public stEmailSendResult SendEmail(PFEmailMessage emailMsg)
        {
            return(SendEmail(emailMsg, true));
        }