コード例 #1
0
        /// <summary>
        /// Will try to send the specified email and returns true for successful sending.
        /// </summary>
        public static bool Send(IEmailQueueItem mailItem)
        {
            if (mailItem == null)
            {
                throw new ArgumentNullException("mailItem");
            }

            if (mailItem.Retries >= MaximumRetries)
            {
                return(false);
            }

            try
            {
                using (var mail = CreateMailMessage(mailItem))
                {
                    if (mail == null)
                    {
                        return(false);
                    }
                    return(EmailDispatcher(mailItem, mail));
                }
            }
            catch (Exception ex)
            {
                OnSendError(mailItem, ex);
                mailItem.RecordRetry();
                Log.Error("Error in sending an email for this EmailQueueItem of '" + mailItem.GetId() + "'", ex);
                return(false);
            }
        }
コード例 #2
0
        /// <summary>
        /// Will try to send the specified email and returns true for successful sending.
        /// </summary>
        public static async Task <bool> Send(IEmailQueueItem mailItem)
        {
            if (mailItem == null)
            {
                throw new ArgumentNullException(nameof(mailItem));
            }

            if (mailItem.Retries >= MaximumRetries)
            {
                return(false);
            }

            MailMessage mail = null;

            try
            {
                using (mail = await CreateMailMessage(mailItem))
                {
                    if (mail == null)
                    {
                        return(false);
                    }
                    return(await EmailDispatcher(mailItem, mail));
                }
            }
            catch (Exception ex)
            {
                await SendError.Raise(new EmailSendingEventArgs(mailItem, mail) { Error = ex });

                await mailItem.RecordRetry();

                Log.Error($"Error in sending an email for this EmailQueueItem of '{mailItem.GetId()}'", ex);
                return(false);
            }
        }