Skip to main content

Module mailer

Module mailer 

Source
Available on crate feature mailer and non-WebAssembly only.
Expand description

Transactional email via SMTP.

Mailer opens a plain or TLS-encrypted TCP connection to an SMTP server, optionally authenticates with AUTH PLAIN, and sends RFC 5321 / RFC 5322 email. No third-party mail library is required.

§Quick start

use rust_web_server::mailer::{Email, Mailer};

let mailer = Mailer::from_env().expect("SMTP config missing");
let email = Email::builder()
    .to("user@example.com")
    .subject("Welcome!")
    .text("Thanks for signing up.")
    .build()
    .unwrap();
mailer.send(&email).expect("send failed");

§Environment variables

VariableDefaultDescription
RWS_SMTP_HOST— (required)SMTP server hostname
RWS_SMTP_PORT587SMTP port
RWS_SMTP_USER—SMTP username; omit to skip AUTH
RWS_SMTP_PASSWORD—SMTP password
RWS_SMTP_FROM— (required)Envelope / From: address
RWS_SMTP_TLSstarttlsTLS mode: starttls, smtps, none
RWS_SMTP_TIMEOUT_MS10000Connect / read / write timeout in ms

§Provider examples

Gmail (STARTTLS, port 587):

RWS_SMTP_HOST=smtp.gmail.com RWS_SMTP_PORT=587 RWS_SMTP_TLS=starttls
RWS_SMTP_USER=you@gmail.com RWS_SMTP_PASSWORD=app-password
RWS_SMTP_FROM=you@gmail.com

SendGrid (STARTTLS, port 587):

RWS_SMTP_HOST=smtp.sendgrid.net RWS_SMTP_PORT=587 RWS_SMTP_TLS=starttls
RWS_SMTP_USER=apikey RWS_SMTP_PASSWORD=SG.xxxx RWS_SMTP_FROM=you@domain.com

Localhost relay (no TLS, port 25):

RWS_SMTP_HOST=127.0.0.1 RWS_SMTP_PORT=25 RWS_SMTP_TLS=none
RWS_SMTP_FROM=app@internal

Structs§

Email
An outgoing email message.
EmailBuilder
Builder for Email.
Mail
An Email with its attachments: what a Deliver sends.
MailAttachment
A file attached to an email.
MailPreviews
Mail previews: pages showing what each email looks like, built from sample data, without sending anything. A middleware: wrap the app in it in development only (it serves whatever the previews render).
Mailer
SMTP mailer.
TestMailbox
Keeps what it’s given instead of sending it: the transport for tests and local development. Clones share the mailbox.

Enums§

MailerError
Error returned by Mailer::send and EmailBuilder::build.
SmtpTls
TLS mode for the SMTP connection.

Constants§

MAIL_JOB_TYPE
The job type of mail put in a PersistentJobQueue by Mail::enqueue.

Traits§

Deliver
Something that sends mail: Mailer (SMTP), TestMailbox (keeps it, for tests and development), or your own (an HTTP email API).

Functions§

register_deliveryjobs and (model-mysql or model-postgres or model-sqlite)
Send the queue’s MAIL_JOB_TYPE jobs through transport (a failed send is retried like any job).