Struct create_rust_app::Mailer

source ·
pub struct Mailer {
    pub from_address: String,
    pub smtp_server: String,
    pub smtp_username: String,
    pub smtp_password: String,
    pub actually_send: bool,
}
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

Implementations§

source§

impl Mailer

source

pub fn new() -> Self

using information stored in the SMTP_FROM_ADDRESS, SMTP_SERVER, SMTP_USERNAME, SMTP_PASSWORD, and SEND_MAIL environment variables to connect to a remote SMTP server,

allows webservers to send emails to users for purposes like marketing, user authentification, etc.

source

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

source

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 recipient
  • subject - subject field of the email
  • text - text content of the email
  • html - html content of the email

Trait Implementations§

source§

impl Clone for Mailer

source§

fn clone(&self) -> Mailer

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Mailer

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for Twhere T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoSql for T

source§

fn into_sql<T>(self) -> Self::Expressionwhere Self: AsExpression<T> + Sized, T: SqlType + TypedExpressionType,

Convert self to an expression for Diesel’s query builder. Read more
source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more