Search

Lib.rs

› Email › async-mailer
#async-smtp #smtp #mailer #async #async-mailer

async-mailer-smtp

Async SMTP mailer implementation, intended to be used as async-mailer generic Mailer or DynMailer trait object

by LeoniePhiline

  • Install
  • API reference
  • GitHub repo (leoniephiline)

12 releases

0.5.0 Mar 12, 2026
0.4.1 Mar 12, 2026
0.4.0 Oct 22, 2024
0.3.2 Apr 5, 2024
0.1.1 May 16, 2023

#642 in Email

Download history 37/week @ 2026-01-14 48/week @ 2026-01-21 56/week @ 2026-01-28 58/week @ 2026-02-04 61/week @ 2026-02-11 47/week @ 2026-02-18 41/week @ 2026-02-25 34/week @ 2026-03-04 22/week @ 2026-03-11 19/week @ 2026-03-18 1/week @ 2026-03-25 1/week @ 2026-04-01 26/week @ 2026-04-08 40/week @ 2026-04-15 20/week @ 2026-04-22 11/week @ 2026-04-29

97 downloads per month
Used in async-mailer

MPL-2.0 license

20KB
137 lines

An SMTP mailer, usable either stand-alone or as either generic Mailer or dynamic dyn DynMailer using the mail-send crate.

Preferably, use async-mailer, which re-exports from this crate, rather than using async-mailer-smtp directly.

You can control the re-exported mailer implementations, as well as tracing support, via async-mailer feature toggles.

Note: If you are planning to always use SmtpMailer and do not need async_mailer_outlook::OutlookMailer or async_mailer::BoxMailer, then consider using the mail-send crate directly.

Examples

Using the statically typed Mailer:

// Both `async_mailer::OutlookMailer` and `async_mailer::SmtpMailer` implement `Mailer`
// and can be used with `impl Mailer` or `<M: Mailer>` bounds.

let mailer = SmtpMailer::new(
    "smtp.example.com".into(),
    465,
    SmtpInvalidCertsPolicy::Deny,
    "<username>".into(),
    secrecy::SecretString::from("<password>")
);

// An alternative `OutlookMailer` can be found at `async-mailer-outlook`.
// 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 = async_mailer_core::mail_send::mail_builder::MessageBuilder::new()
    .from(("From Name", "from@example.com"))
    .to("to@example.com")
    .subject("Subject")
    .text_body("Mail body")
    .into_message()?;

// Send the message using the statically typed `Mailer`.

mailer.send_mail(message).await?;

Using the dynamically typed DynMailer:

// Both `async_mailer::OutlookMailer` and `async_mailer::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 = SmtpMailer::new_box( // Or `SmtpMailer::new_arc()`.
    "smtp.example.com".into(),
    465,
    SmtpInvalidCertsPolicy::Deny,
    "<username>".into(),
    secrecy::SecretString::from("<password>")
);

// An alternative `OutlookMailer` can be found at `async-mailer-outlook`.
// 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 = async_mailer_core::mail_send::mail_builder::MessageBuilder::new()
    .from(("From Name", "from@example.com"))
    .to("to@example.com")
    .subject("Subject")
    .text_body("Mail body")
    .into_message()?;

// Send the message using the implementation-agnostic `dyn DynMailer`.

mailer.send_mail(message).await?;

Feature flags

  • tracing: Enable debug and error logging using the tracing crate. All relevant functions are instrumented.
  • clap: Implement clap::ValueEnum for SmtpInvalidCertsPolicy. This allows for easily configured CLI options like --invalid-certs <allow|deny>.

Default: tracing.

Roadmap

DKIM support is planned to be implemented on the SmtpMailer.

Dependencies

~16–32MB
~486K SLoC

  • async-mailer-core
  • async-trait
  • optional clap+derive
  • secrecy 0.10
  • thiserror 2.0
  • default tracing
Related: async-mailer, async-mailer-core, async-mailer-outlook
See also: async-smtp, lettre, indymilter-test, mailify-lib, opentalk-mail-worker-protocol, eternaltwin_mailer, smtp, mail-message, maily, mail-send, himalaya

Lib.rs is an unofficial list of Rust/Cargo crates, created by kornelski. It contains data from multiple sources, including heuristics, and manually curated data. Content of this page is not necessarily endorsed by the authors of the crate. This site is not affiliated with nor endorsed by the Rust Project. If something is missing or incorrect, please file a bug.