Mailer

Trait Mailer 

Source
pub trait Mailer: Send + Sync {
    // Required method
    fn deliver<'life0, 'life1, 'async_trait>(
        &'life0 self,
        email: &'life1 Email,
    ) -> Pin<Box<dyn Future<Output = Result<DeliveryResult, MailError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn validate_batch(&self, _emails: &[Email]) -> Result<(), MailError> { ... }
    fn deliver_many<'life0, 'life1, 'async_trait>(
        &'life0 self,
        emails: &'life1 [Email],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<DeliveryResult>, MailError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn provider_name(&self) -> &'static str { ... }
    fn validate_config(&self) -> Result<(), MailError> { ... }
}
Expand description

Trait for email delivery providers.

All email providers (SMTP, Resend, SendGrid, etc.) implement this trait.

§Example

use missive::{Email, Mailer};
use missive::providers::SmtpMailer;

let mailer = SmtpMailer::new("smtp.example.com", 587, "user", "pass");

let email = Email::new()
    .from("sender@example.com")
    .to("recipient@example.com")
    .subject("Hello")
    .text_body("World");

let result = mailer.deliver(&email).await?;
println!("Sent with ID: {}", result.message_id);

Required Methods§

Source

fn deliver<'life0, 'life1, 'async_trait>( &'life0 self, email: &'life1 Email, ) -> Pin<Box<dyn Future<Output = Result<DeliveryResult, MailError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Send a single email.

Returns the message ID on success.

Provided Methods§

Source

fn validate_batch(&self, _emails: &[Email]) -> Result<(), MailError>

Validate emails before batch sending.

Override this in providers that have batch limitations. Called by deliver_many() before sending.

§Example
fn validate_batch(&self, emails: &[Email]) -> Result<(), MailError> {
    for email in emails {
        if !email.attachments.is_empty() {
            return Err(MailError::UnsupportedFeature(
                "attachments not supported in batch sends".into()
            ));
        }
    }
    Ok(())
}
Source

fn deliver_many<'life0, 'life1, 'async_trait>( &'life0 self, emails: &'life1 [Email], ) -> Pin<Box<dyn Future<Output = Result<Vec<DeliveryResult>, MailError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Send multiple emails.

Default implementation calls validate_batch() first, then deliver() for each email. Providers with batch APIs can override for better performance.

Source

fn provider_name(&self) -> &'static str

Get the provider name (for logging/debugging).

Source

fn validate_config(&self) -> Result<(), MailError>

Validate configuration.

Called at startup to verify required configuration is present. Override in providers that require specific config (API keys, etc.).

Implementors§