async-mailer
A set of async generic Mailer and dynamic dyn DynMailer traits with runtime-pluggable Microsoft Outlook (Office365) and SMTP implementations.
Installation
Add to your Cargo.toml:
= "0.4.1"
You can control the re-exported mailer implementations,
as well as tracing support,
via crate feature toggles.
By default, features smtp, outlook and tracing are enabled.
Use default-features = false and features = [...] to select features individually.
Examples:
Use new for a statically typed mailer instance,
or new_box / new_arc for a type-erased dynamic mailer.
Microsoft Outlook (Office365) and SMTP variants are available.
Using the statically typed Mailer:
// Both `OutlookMailer` and `SmtpMailer` implement `Mailer`
// and can be used with `impl Mailer` or `<M: Mailer>` bounds.
use ;
let mailer: OutlookMailer = new.await?;
// Alternative:
let mailer: SmtpMailer = new;
// Further alternative mailers can be implemented by third parties.
// 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 = new
.from
.to
.subject
.text_body
.into_message?;
// Send the message using the statically typed `Mailer`.
mailer.send_mail.await?;
Using the dynamically typed dyn DynMailer / BoxMailer / ArcMailer:
use ;
// Both `OutlookMailer` and `SmtpMailer` implement `DynMailer` and can be used as trait objects.
// Here they are used as `BoxMailer`, which is an alias to `Box<dyn DynMailer>`.
let mailer: BoxMailer = new_box.await?;
// Alternative:
let mailer: BoxMailer = new_box;
// Further alternative mailers can be implemented by third parties.
// The trait object is `Send` and `Sync` and may be stored e.g. as part of your server state.
// 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 = new
.from
.to
.subject
.text_body
.into_message?;
// Send the message using the implementation-agnostic `dyn DynMailer`.
mailer.send_mail.await?;
Feature flags
outlook: EnableOutlookMailer.smtp: EnableSmtpMailer.tracing: Enable debug and error logging using thetracingcrate.clap: Implementclap::ValueEnumforSmtpInvalidCertsPolicy. This allows for easily configured CLI options like--invalid-certs <allow|deny>.
Default: outlook, smtp, tracing.
Roadmap
- DKIM support is planned to be implemented on the
SmtpMailer. - Access token auto-refresh is planned to be implemented on the
OutlookMailer.
Further mailer implementations are possible. Please open an issue and ideally provide a pull request to add your alternative mailer implementation!