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
| Variable | Default | Description |
|---|---|---|
RWS_SMTP_HOST | — (required) | SMTP server hostname |
RWS_SMTP_PORT | 587 | SMTP port |
RWS_SMTP_USER | — | SMTP username; omit to skip AUTH |
RWS_SMTP_PASSWORD | — | SMTP password |
RWS_SMTP_FROM | — (required) | Envelope / From: address |
RWS_SMTP_TLS | starttls | TLS mode: starttls, smtps, none |
RWS_SMTP_TIMEOUT_MS | 10000 | Connect / 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.comSendGrid (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.comLocalhost relay (no TLS, port 25):
RWS_SMTP_HOST=127.0.0.1 RWS_SMTP_PORT=25 RWS_SMTP_TLS=none
RWS_SMTP_FROM=app@internalStructs§
- An outgoing email message.
- Email
Builder - Builder for
Email. - Mailer
- SMTP mailer.
Enums§
- Mailer
Error - Error returned by
Mailer::sendandEmailBuilder::build. - SmtpTls
- TLS mode for the SMTP connection.