rok-mail 0.6.0

Email support for the rok ecosystem — Mailable trait, log/SMTP drivers
Documentation
#[derive(Debug, Clone)]
pub struct MailConfig {
    /// Driver to use: "log" (default, prints to stdout) or "smtp".
    pub driver: String,
    /// Envelope from address.
    pub from_address: String,
    /// Display name for the from address.
    pub from_name: String,
    /// Default reply-to address.
    pub reply_to: Option<String>,
    /// SMTP host (required when driver = "smtp").
    pub smtp_host: Option<String>,
    /// SMTP port. Default: 587.
    pub smtp_port: u16,
    /// SMTP username for authentication.
    pub smtp_username: Option<String>,
    /// SMTP password for authentication.
    pub smtp_password: Option<String>,
    /// Encryption mode: "starttls" (default), "tls", or "none".
    pub smtp_encryption: String,
    /// API key for the Postmark driver.
    pub postmark_api_key: Option<String>,
    /// API key for the Resend driver.
    pub resend_api_key: Option<String>,
}

impl MailConfig {
    /// Set the default from address and display name (builder style).
    pub fn from(mut self, address: impl Into<String>, name: impl Into<String>) -> Self {
        self.from_address = address.into();
        self.from_name = name.into();
        self
    }

    /// Set the default reply-to address.
    pub fn reply_to(mut self, address: impl Into<String>) -> Self {
        self.reply_to = Some(address.into());
        self
    }

    /// Set the SMTP host (builder style).
    pub fn smtp_host(mut self, host: impl Into<String>) -> Self {
        self.smtp_host = Some(host.into());
        self
    }

    /// Set the SMTP port (builder style).
    pub fn smtp_port(mut self, port: u16) -> Self {
        self.smtp_port = port;
        self
    }

    /// Set the Postmark API key (builder style).
    pub fn postmark_key(mut self, key: impl Into<String>) -> Self {
        self.postmark_api_key = Some(key.into());
        self
    }

    /// Set the Resend API key (builder style).
    pub fn resend_key(mut self, key: impl Into<String>) -> Self {
        self.resend_api_key = Some(key.into());
        self
    }
}

impl Default for MailConfig {
    fn default() -> Self {
        Self {
            driver: "log".into(),
            from_address: "noreply@rok-app.com".into(),
            from_name: "rok-app".into(),
            reply_to: None,
            smtp_host: None,
            smtp_port: 587,
            smtp_username: None,
            smtp_password: None,
            smtp_encryption: "starttls".into(),
            postmark_api_key: None,
            resend_api_key: None,
        }
    }
}