/// <summary> /// Will try to send the specified email and returns true for successful sending. /// </summary> public static async Task <bool> Send(IEmailMessage 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); } }
/// <summary> /// Will try to send the specified email and returns true for successful sending. /// </summary> public static async Task <bool> Send(IEmailMessage 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); } await Sending.Raise(new EmailSendingEventArgs(mailItem, mail)); var dispatcher = Context.Current.GetOptionalService <IEmailDispatcher>() ?? new DefaultEmailDispatcher(); var result = await dispatcher.Dispatch(mailItem, mail); await Sent.Raise(new EmailSendingEventArgs(mailItem, mail)); return(result); } } catch (Exception ex) { await SendError.Raise(new EmailSendingEventArgs(mailItem, mail) { Error = ex }); await mailItem.RecordRetry(); Log.For(typeof(EmailService)) .Error(ex, $"Error in sending an email for this EmailQueueItem of '{mailItem.GetId()}'"); return(false); } }