Skip to main content

Mailable

Trait Mailable 

Source
pub trait Mailable {
    const TEMPLATE: &'static str;

    // Provided methods
    fn build(&self, base: Email) -> Email { ... }
    fn context(&self) -> Context { ... }
    fn render(&self, renderer: &EmailRenderer) -> Result<Email, MailableError> { ... }
    fn send<'a>(
        &'a self,
        renderer: &'a EmailRenderer,
        mailer: &'a BoxedMailer,
    ) -> Pin<Box<dyn Future<Output = Result<(), MailableError>> + Send + 'a>>
       where Self: Sync { ... }
    fn dispatch<'a, Q>(
        &'a self,
        renderer: &'a EmailRenderer,
        queue: &'a Q,
    ) -> Pin<Box<dyn Future<Output = Result<(), MailableError>> + Send + 'a>>
       where Self: Sync,
             Q: JobQueue + Sync { ... }
}
Expand description

One sendable email kind. The struct carries the per-email data, such as recipient, ids and URLs, and this trait ties it to a Tera template and to the addresses.

Required Associated Constants§

Source

const TEMPLATE: &'static str

Template base name. The renderer looks for {TEMPLATE}.subject.txt, {TEMPLATE}.txt and, if present, {TEMPLATE}.html.

Provided Methods§

Source

fn build(&self, base: Email) -> Email

Set recipients, sender, reply-to and headers on the rendered Email. The default returns it unchanged, so override this and add at least one .to(...).

Source

fn context(&self) -> Context

The Tera context for the template. Defaults to empty.

Source

fn render(&self, renderer: &EmailRenderer) -> Result<Email, MailableError>

Render the email and return it ready to send.

§Errors

Render(_) when the template is missing or fails to render.

Source

fn send<'a>( &'a self, renderer: &'a EmailRenderer, mailer: &'a BoxedMailer, ) -> Pin<Box<dyn Future<Output = Result<(), MailableError>> + Send + 'a>>
where Self: Sync,

Render and send in the current request.

§Errors

Render(_) for template errors, Send(_) when the mailer fails, for example a refused recipient or a transport error.

Source

fn dispatch<'a, Q>( &'a self, renderer: &'a EmailRenderer, queue: &'a Q, ) -> Pin<Box<dyn Future<Output = Result<(), MailableError>> + Send + 'a>>
where Self: Sync, Q: JobQueue + Sync,

Render now and put the email on the crate::jobs queue. This returns at once; a worker delivers it.

§Errors

Render(_) for template errors. A queue error comes back as Send(_) carrying the message text.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§