pub struct MailConfig {
pub driver: MailDriver,
pub from: String,
pub from_name: Option<String>,
pub smtp: Option<SmtpConfig>,
pub resend: Option<ResendConfig>,
}Expand description
Mail configuration supporting multiple drivers.
Fields§
§driver: MailDriverWhich driver to use.
from: StringDefault from address (shared across all drivers).
from_name: Option<String>Default from name (shared across all drivers).
smtp: Option<SmtpConfig>SMTP-specific config (only when driver = Smtp).
resend: Option<ResendConfig>Resend-specific config (only when driver = Resend).
Implementations§
Source§impl MailConfig
impl MailConfig
Sourcepub fn new(host: impl Into<String>, port: u16, from: impl Into<String>) -> Self
pub fn new(host: impl Into<String>, port: u16, from: impl Into<String>) -> Self
Create a new SMTP mail config (backwards compatible).
Sourcepub fn resend(api_key: impl Into<String>, from: impl Into<String>) -> Self
pub fn resend(api_key: impl Into<String>, from: impl Into<String>) -> Self
Create a new Resend mail config.
Sourcepub fn from_env() -> Option<Self>
pub fn from_env() -> Option<Self>
Create mail configuration from environment variables.
Returns None if required variables are missing.
Reads the following environment variables:
MAIL_DRIVER: “smtp” (default) or “resend”MAIL_FROM_ADDRESS: Default from email address (required for all drivers)MAIL_FROM_NAME: Default from name (optional)
SMTP driver variables:
MAIL_HOST: SMTP server host (required)MAIL_PORT: SMTP server port (default: 587)MAIL_USERNAME: SMTP username (optional)MAIL_PASSWORD: SMTP password (optional)MAIL_ENCRYPTION: “tls” or “none” (default: “tls”)
Resend driver variables:
RESEND_API_KEY: Resend API key (required)
§Example
ⓘ
use ferro_notifications::MailConfig;
if let Some(config) = MailConfig::from_env() {
// Mail is configured
}Trait Implementations§
Source§impl Clone for MailConfig
impl Clone for MailConfig
Source§fn clone(&self) -> MailConfig
fn clone(&self) -> MailConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MailConfig
impl RefUnwindSafe for MailConfig
impl Send for MailConfig
impl Sync for MailConfig
impl Unpin for MailConfig
impl UnsafeUnpin for MailConfig
impl UnwindSafe for MailConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more