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>,
) -> MailConfig
pub fn new( host: impl Into<String>, port: u16, from: impl Into<String>, ) -> MailConfig
Create a new SMTP mail config (backwards compatible).
Sourcepub fn resend(api_key: impl Into<String>, from: impl Into<String>) -> MailConfig
pub fn resend(api_key: impl Into<String>, from: impl Into<String>) -> MailConfig
Create a new Resend mail config.
Sourcepub fn from_env() -> Option<MailConfig>
pub fn from_env() -> Option<MailConfig>
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>,
) -> MailConfig
pub fn credentials( self, username: impl Into<String>, password: impl Into<String>, ) -> MailConfig
Set SMTP credentials.
Sourcepub fn from_name(self, name: impl Into<String>) -> MailConfig
pub fn from_name(self, name: impl Into<String>) -> MailConfig
Set the from name.
Sourcepub fn no_tls(self) -> MailConfig
pub fn no_tls(self) -> MailConfig
Disable TLS (SMTP only).
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
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>
Converts
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>
Converts
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