Rust

email

Module

Email adapters: Smtp (and Mock, SMTP to a catcher), Ses, Mailgun, Sendgrid and Resend, with mime, the MIME message SMTP and SES send.

Contents

6 submodules, and what the module defines itself.

use utopia_messaging::email::format_address;
Rust
pub fn format_address(email: &str, name: Option<&str>) -> String

An address with an optional display name, the name quoted when it carries RFC 5322 specials ("Acme, Inc." <a@example.com>).

Rust
pub const MAX_ATTACHMENT_BYTES: u64 = 25 * 1024 * 1024

The attachment limit of an email adapter, unless it says otherwise.

Rust
pub const TYPE: &str = "email"

The kind of every email adapter.

email::mailgun

Own page
use utopia_messaging::email::mailgun::Mailgun;
Rust
pub struct Mailgun

Mailgun's messages API, one batch request for every recipient (recipient variables keep them from seeing each other).

email::mime

Own page

An email as a MIME message on the wire, which the SMTP adapter hands over whole and SES sends as a raw message per recipient.

use utopia_messaging::email::mime::addresses;
Rust
pub fn addresses(recipients: &[Mailbox]) -> Result<Vec<Address>, Error>

The recipients as addresses (a missing name is empty).

use utopia_messaging::email::mime::attachments;
Rust
pub fn attachments(email: &Email) -> Result<Vec<Attachment>, Error>

The email's attachments: read from their path when written, or from the content given.

use utopia_messaging::email::mime::message;
Rust
pub fn message(email: &Email, to: &[Mailbox], cc: &[Mailbox], bcc: &[Mailbox], headers: &[(String, String)]) -> Result<Message, Error>

The message for email, addressed to to and cc, with bcc in the envelope only, and headers of the adapter's own (X-Mailer), which win over the email's headers of the same name in any case.

The text part is the content, or for HTML the content without style blocks and tags.

use utopia_messaging::email::mime::size;
Rust
pub fn size(email: &Email) -> Result<u64, Error>

What the attachments weigh before they are encoded.

Fails with Error::Exception for a file that cannot be read.

email::resend

Own page
use utopia_messaging::email::resend::Resend;
Rust
pub struct Resend

Resend's email API: one batch request, or one request per recipient when there are attachments (batches cannot carry them).

Rust
pub const MAX_ATTACHMENT_BYTES: u64 = 40 * 1024 * 1024

Resend's attachment limit.

email::sendgrid

Own page
use utopia_messaging::email::sendgrid::Sendgrid;
Rust
pub struct Sendgrid

SendGrid's mail send API: one request, a personalization per recipient.

email::ses

Own page
use utopia_messaging::email::ses::Ses;
Rust
pub struct Ses

Amazon SES over the v2 API, signed with AWS Signature Version 4.

Without attachments, one SendBulkEmail request carries every recipient, with the content registered once as a template named after its hash (created on first use, never deleted). With attachments, one SendEmail request per recipient carries a raw MIME message.

Rust
pub const MAX_ATTACHMENT_BYTES: u64 = 10 * 1024 * 1024

SES's limit on a whole MIME message.

Rust
pub const MAX_DESTINATIONS: i64 = 50

SES's cap on destinations per bulk request.

email::smtp

Own page
use utopia_messaging::email::smtp::Host;
Rust
pub struct Host

A server to try: host (an address literal stays bracketed), port and encryption.

use utopia_messaging::email::smtp::Mock;
Rust
pub struct Mock

The SMTP adapter pointed at a mail catcher: no credentials, no encryption, X-Mailer: Utopia Mailer, and named Mock.

use utopia_messaging::email::smtp::NoHostAnswered;
Rust
pub struct NoHostAnswered

Every host in the list failed before a session was open: the message names each host's failure, and permanent says whether trying the list again can go differently (only when every host refused for good).

use utopia_messaging::email::smtp::Smtp;
Rust
pub struct Smtp

An SMTP relay: one or several hosts tried in order, with STARTTLS or implicit TLS, PLAIN or LOGIN authentication, and optionally a session kept open across sends. Every recipient gets the server's own answer.

Also implements Debug.