Crate async_mailer
source ·Expand description
Create a dynamic mailer trait object depending on runtime mailer configuration.
Microsoft Outlook and SMTP mailer variants are available.
Example:
// Outlook configuration, e.g. from command line arguments or environment variables.
let mailer_configuration = MailerConfiguration::Outlook {
tenant: "<Microsoft Identity service tenant>",
app_guid: "<OAuth2 app GUID>",
secret: "<OAuth2 app secret>"
};
// Alternative: SMTP configuration, e.g. from command line arguments or environment variables.
let mailer_configuration = MailerConfiguration::Outlook {
host: "smtp.example.com",
port: 465,
invalid_certs: SmtpInvalidCertsPolicy::Deny,
user: "<username>",
password: "<password>"
};
// Create a `Box<dyn Mailer>`.
// The implementation is `Send` and `Sync` and may be store e.g. as part of your server state.
let mailer = new_mailer(mailer_configuration).await?;
// Build a message using the re-exported `mail_builder::MessageBuilder'.
// For blazingly fast rendering of beautiful HTML mail, I recommend combining `askama` with `mrml`.
let message = MessageBuilder::new()
.from(("From Name", "from@example.com"))
.to("to@example.com")
.subject("Subject")
.text_body("Mail body");
// Send the message using the implementation-agnostic `dyn Mailer`.
mailer.send_mail(&message).await?;Structs
- Builds an RFC5322 compliant MIME email message.
- An Outlook mailer client, implementing the
async_mailer::Mailertrait to be used as runtime-pluggable trait object. - Wrapper type for values that contains secrets, which attempts to limit accidental exposure and ensure secrets are wiped from memory when dropped. (e.g. passwords, cryptographic keys, access tokens or other credentials)
- An SMTP mailer client, implementing the
async_mailer::Mailertrait to be used as runtime-pluggable trait object.
Enums
- Mailer configuration helper, which can be used with clap.
- Error returned by
OutlookMailer::newif an access token cannot be retrieved. - Error returned by
OutlookMailer::newandOutlookMailer::send_mail. - Pass to
SmtpMailer::newto either allow or deny invalid SMTP certificates. - Error returned by
SmtpMailer::newandSmtpMailer::send_mail.
Traits
Functions
- Create a new dynamic mailer trait object depending on the provided
MailerConfiguration.
Type Definitions
- Type-erased mailer error, for use of
Maileras trait object.