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
}Sourcepub fn credentials(
self,
username: impl Into<String>,
password: impl Into<String>,
) -> Self
pub fn credentials( self, username: impl Into<String>, password: impl Into<String>, ) -> Self
Set SMTP credentials.
No-ops with a warning when the driver is not MailDriver::Smtp — calling
credentials(...) on a Resend config is almost certainly a caller mistake
and should not silently mutate the config into an SMTP shape.
Trait Implementations§
Source§impl Clone for MailConfig
impl Clone for MailConfig
Source§fn clone(&self) -> MailConfig
fn clone(&self) -> MailConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more