#outlook #async #mailer

async-mailer-outlook

Async Outlook (Office365) mailer implementation, intended to be used as async-mailer generic Mailer or DynMailer trait object

11 releases

0.4.0 Oct 22, 2024
0.3.2 Apr 5, 2024
0.3.0 Oct 24, 2023
0.2.3 May 31, 2023
0.1.2 May 16, 2023

#272 in Email

Download history 3/week @ 2024-07-18 9/week @ 2024-07-25 3/week @ 2024-08-01 35/week @ 2024-08-15 36/week @ 2024-08-22 27/week @ 2024-08-29 26/week @ 2024-09-05 27/week @ 2024-09-12 35/week @ 2024-09-19 59/week @ 2024-09-26 47/week @ 2024-10-03 35/week @ 2024-10-10 132/week @ 2024-10-17 39/week @ 2024-10-24 14/week @ 2024-10-31

226 downloads per month
Used in async-mailer

MPL-2.0 license

25KB
199 lines

An Outlook mailer, usable either stand-alone or as either generic Mailer or dynamic dyn DynMailer.

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

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

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 = OutlookMailer::new(
    "<Microsoft Identity service tenant>".into(),
    "<OAuth2 app GUID>".into(),
    secrecy::SecretString::from("<OAuth2 app secret>")
).await?;

// An alternative `SmtpMailer` can be found at `async-mailer-smtp`.
// 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 = OutlookMailer::new_box( // Or `OUtlookMailer::new_arc()`.
    "<Microsoft Identity service tenant>".into(),
    "<OAuth2 app GUID>".into(),
    secrecy::SecretString::from("<OAuth2 app secret>")
).await?;

// An alternative `SmtpMailer` can be found at `async-mailer-smtp`.
// 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.

Default: tracing.

Roadmap

Access token auto-refresh is planned to be implemented on the OutlookMailer.

Dependencies

~15–29MB
~545K SLoC