/// <summary> /// Sends MandrillMessage asynchronously using tasks. /// </summary> /// <param name="mailAttributes">The IMailAttributes message you wish to send.</param> public async Task<IMailAttributes> SendAsync(IMailAttributes mailAttributes) { EmailMessage mail = ((MandrillMailAttributes) mailAttributes).GenerateProspectiveMailMessage(); await _client.SendMessageAsync(mail); return mailAttributes; }
/// <summary> /// Initializes MailerBase using the defaultMailSender and system Encoding. /// </summary> /// <param name="mailAttributes"> the mail attributes</param> /// <param name="mailSender">The underlying mail sender to use for delivering mail.</param> protected MailerBase(IMailAttributes mailAttributes = null, IMailSender mailSender = null) { MailAttributes = mailAttributes ?? MailMethodUtil.GetAttributes(); MailSender = mailSender ?? MailMethodUtil.GetSender(); if (System.Web.HttpContext.Current == null) return; HttpContextBase = new HttpContextWrapper(System.Web.HttpContext.Current); RouteData routeData = RouteTable.Routes.GetRouteData(HttpContextBase) ?? new RouteData(); var requestContext = new RequestContext(HttpContextBase, routeData); base.Initialize(requestContext); }
/// <summary> /// Sends async the given email /// </summary> /// <param name="mail">The mail message to send.</param> public async Task<IMailAttributes> DeliverAsync(IMailAttributes mail) { if (mail == null) throw new ArgumentNullException("mail"); var mailContext = new MailSendingContext(mail); _interceptor.OnMailSending(mailContext); if (mailContext.Cancel) return null; Task<IMailAttributes> sendtask = _sender.SendAsync(mail); await sendtask.ContinueWith(t => AsyncSendCompleted(t.Result)); return mail; }
/// <summary> /// Sends the given email /// </summary> /// <param name="mail">The mail message to send.</param> public IMailAttributes Deliver(IMailAttributes mail) { if (mail == null) throw new ArgumentNullException("mail"); var mailContext = new MailSendingContext(mail); _interceptor.OnMailSending(mailContext); if (mailContext.Cancel) return null; _sender.Send(mail); _interceptor.OnMailSent(mail); return mail; }
/// <summary> /// Creates a new EmailResult. You must call ExecuteCore() before this result /// can be successfully delivered. /// </summary> /// <param name="interceptor">The IMailInterceptor that we will call when delivering mail.</param> /// <param name="sender">The IMailSender that we will use to send mail.</param> /// <param name="mail">The mail messageBase who's body needs populating.</param> /// <param name="viewName">The view to use when rendering the messageBase body (can be null)</param> /// <param name="masterName">The maste rpage to use when rendering the messageBase body (can be null)</param> /// <param name="messageEncoding">The encoding to use when rendering a messageBase.</param> /// <param name="trimBody">Whether or not we should trim whitespace from the beginning and end of the messageBase body.</param> public EmailResult(IMailInterceptor interceptor, IMailSender sender, IMailAttributes mail, string viewName, string masterName, Encoding messageEncoding, bool trimBody) { if (interceptor == null) throw new ArgumentNullException("interceptor"); if (sender == null) throw new ArgumentNullException("sender"); if (mail == null) throw new ArgumentNullException("mail"); ViewName = viewName ?? ViewName; MasterName = masterName ?? MasterName; _messageEncoding = messageEncoding; _mail = mail; _mailSender = sender; _interceptor = interceptor; _deliveryHelper = new DeliveryHelper(_mailSender, _interceptor); _trimBody = trimBody; }
public void SetMailMethod(MailMethod method) { MailAttributes = MailMethodUtil.GetAttributes(method); MailSender = MailMethodUtil.GetSender(method); }
/// <summary> /// This method is called after each mail is sent. /// </summary> /// <param name="mail">The mail that was sent.</param> protected virtual void OnMailSent(IMailAttributes mail) { }
void IMailInterceptor.OnMailSent(IMailAttributes mail) { OnMailSent(mail); }
private void AsyncSendCompleted(IMailAttributes mail) { _interceptor.OnMailSent(mail); }
public TestMailerBase(IMailAttributes attributes = null, IMailSender sender = null) : base(attributes, sender) { }
/// <summary> /// Sends SMTPMailMessage synchronously. /// </summary> /// <param name="mailAttributes">The SmtpMailAttributes you wish to send.</param> public void Send(IMailAttributes mailAttributes) { MailMessage mail = ((SmtpMailAttributes) mailAttributes).GenerateProspectiveMailMessage(); _client.Send(mail); }
/// <summary> /// Returns a populated context to be used for the OnMailSending() /// method in MailerBase. /// </summary> /// <param name="mail">The message you wish to wrap within this context.</param> public MailSendingContext(IMailAttributes mail) { Mail = mail; Cancel = false; }
/// <summary> /// Sends MandrillMessage synchronously. /// </summary> /// <param name="mailAttributes">The IMailAttributes you wish to send.</param> public void Send(IMailAttributes mailAttributes) { EmailMessage mail = ((MandrillMailAttributes) mailAttributes).GenerateProspectiveMailMessage(); _client.SendMessage(mail); }