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.
Mailer
SMTP mailer.

Enums§

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