Expand description
rustlavel-mail: sending email, and notifications that fan out to several channels from one definition.
The SMTP client is written here, on Tokio’s TCP, the same way the HTTP server and the PostgreSQL driver are — only TLS is delegated, to rustls.
ⓘ
use rustlavel_mail::{Mail, Message};
let mailer = Mail::from_config(&config)?;
mailer.send(
Message::new()
.to(("Ada Lovelace", "ada@example.com"))
.subject("Your receipt")
.html("<p>Thank you.</p>"),
).await?;§The three transports
mail.transport picks one, and nothing else in an application changes:
log— writes the rendered message to the log. The local default: mail you can read without a mail server, an inbox, or a network.file— one.emlper message undermail.path, which any mail client will open, so a designer can look at the real thing.smtp— the real one.
§Testing
Mail::fake records what would have been sent and sends nothing, so a
test can assert on the subject and the body without a server anywhere:
ⓘ
let mailer = Mail::fake();
ship_the_order(&mailer).await?;
mailer.fake().unwrap().assert_sent_to("ada@example.com");Re-exports§
pub use address::Address;pub use address::IntoAddress;pub use config::MailConfig;pub use config::TransportKind;pub use fake::Fake;pub use mailable::Mailable;pub use mailable::html_to_text;pub use message::Attachment;pub use message::Message;pub use notification::Delivery;pub use notification::Notification;pub use notification::Notified;pub use notification::Notifier;pub use notification::Recipient;pub use notification::channel;pub use smtp::Encryption;pub use smtp::Reply;pub use smtp::SmtpClient;pub use smtp::SmtpConfig;pub use transport::FileTransport;pub use transport::LogTransport;pub use transport::Mailer;pub use transport::SmtpTransport;pub use transport::Transport;
Modules§
- address
- Email addresses, and the display names attached to them.
- config
- Mail configuration, read from
config/mail.jsonor.env. - encode
- The encodings a message has to speak.
- fake
- Faking outbound mail.
- mailable
- A type that describes its own email.
- message
- Building a message, and turning it into MIME.
- notification
- Notifications: one definition, several channels.
- smtp
- SMTP, written here rather than taken from a crate.
- transport
- Where a message actually goes: a mail server, the log, or a directory.
Structs§
- The entry point, in the shape Laravel’s
Mailfacade has.