pub struct Mailer {
pub from_address: String,
pub smtp_server: String,
pub smtp_username: String,
pub smtp_password: String,
pub actually_send: bool,
pub templates: Box<dyn EmailTemplates + Sync + Send>,
}
Expand description
struct used to handle sending emails
Fields§
§from_address: String
the email address emails should be sent from
set by the SMTP_FROM_ADDRESS
environment variable
smtp_server: String
the smtp server to connect to for purposes of sending emails
set by the SMTP_SERVER
environment variable
smtp_username: String
username used to log into SMTP_SERVER
set by the SMTP_USERNAME
environment variable
smtp_password: String
the password used to log into SMTP_SERVER
set by the SMTP_PASSWORD
environment variable
actually_send: bool
whether or not emails should actually be sent when requested
it may be useful to set this to false in some devolopment environments while setting it to true in production
set by the SEND_MAIL
environment variable
templates: Box<dyn EmailTemplates + Sync + Send>
Implementations§
Source§impl Mailer
impl Mailer
pub fn new(templates: Box<dyn EmailTemplates + Sync + Send>) -> Self
Sourcepub fn check_environment_variables()
pub fn check_environment_variables()
checks that the required environment variables are set
prints messages denoting which, if any, of the required environment variables were not set
§Panics
panics if any of the required environment variables aren’t set properly
TODO: it’d be better to return a Result and let the user handle the error
Sourcepub fn send(&self, to: &str, subject: &str, text: &str, html: &str)
pub fn send(&self, to: &str, subject: &str, text: &str, html: &str)
send an email with the specifified content and subject to the specified user
will only send an email if the SEND_MAIL
environment variable was set to true when
this mailer was initialized.
§Arguments
to
- a string slice that holds the email address of the intended recipientsubject
- subject field of the emailtext
- text content of the emailhtml
- html content of the email
§Panics
panis if the to
argument is not a valid email address
TODO: wouldn’t it be better to instead require the to
argument be some wrapper around a string that is always a valid email address?
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Mailer
impl !RefUnwindSafe for Mailer
impl Send for Mailer
impl Sync for Mailer
impl Unpin for Mailer
impl !UnwindSafe for Mailer
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 moreSource§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self
to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self
to an expression for Diesel’s query builder. Read more