A set of async generic Mailer and dynamic dyn DynMailer traits with runtime-pluggable Microsoft Outlook (Office365) and SMTP implementations.
Add to your Cargo.toml:
toml
async-mailer = "0.3.5"
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.
Use new for a strongly typed mailer instance,
or new_box / new_arc for a type-erased dynamic mailer.
Microsoft Outlook (Office365) and SMTP variants are available.
Mailer:``rust
// BothOutlookMailerandSmtpMailerimplementMailer
// and can be used withimpl Maileror
use async_mailer::{ IntoMessage, Mailer, OutlookMailer, SmtpMailer };
let mailer: OutlookMailer = OutlookMailer::new(
"
// Alternative:
let mailer: SmtpMailer = SmtpMailer::new(
"smtp.example.com".into(),
465,
asyncmailer::SmtpInvalidCertsPolicy::Deny,
"
// 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 combiningaskamawithmrml`.
let message = asyncmailer::MessageBuilder::new() .from(("From Name", "from@example.com")) .to("to@example.com") .subject("Subject") .textbody("Mail body") .into_message()?;
// Send the message using the strongly typed Mailer.
mailer.send_mail(message).await?; ```
dyn DynMailer / BoxMailer / ArcMailer:```rust use async_mailer::{ BoxMailer, IntoMessage, OutlookMailer, SmtpMailer };
// 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 = OutlookMailer::newbox( // Or OutlookMailer::new_arc().
"
// Alternative:
let mailer: BoxMailer = SmtpMailer::newbox( // Or SmtpMailer::new_arc().
"smtp.example.com".into(),
465,
asyncmailer::SmtpInvalidCertsPolicy::Deny,
"
// 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 combiningaskamawithmrml`.
let message = asyncmailer::MessageBuilder::new() .from(("From Name", "from@example.com")) .to("to@example.com") .subject("Subject") .textbody("Mail body") .into_message()?;
// Send the message using the implementation-agnostic dyn DynMailer.
mailer.send_mail(message).await?; ```
outlook: Enable OutlookMailer.smtp: Enable SmtpMailer.tracing: Enable debug and error logging using the tracing crate.clap: Implement clap::ValueEnum
for SmtpInvalidCertsPolicy.
This allows for easily configured CLI options like --invalid-certs <allow|deny>.Default: outlook, smtp, tracing.
SmtpMailer.OutlookMailer.Further mailer implementations are possible. Please open an issue and ideally provide a pull request to add your alternative mailer implementation!