This guide is for an unreleased version of Cot.
If that's not what you want, check out the latest version!
Sending Emails
Cot provides a unified interface for sending emails, allowing you to switch between different email backends (like SMTP, Memory, or Console) easily. This is powered by the popular lettre crate.
Configuration
To use the email system, you need to enable the email feature in cot and configure it.
Enabling the Feature
In your Cargo.toml:
[]
= { = "0.5", = ["email"] }
Configuration via TOML
Configure the email transport in your config/*.toml files:
[]
= "[email protected]" # Default sender address (optional)
[]
= "smtp" # Options: "smtp", "console"
= "smtp://user:password@localhost:587" # For SMTP
= "plain" # or "login", "xoauth2"
For development, you might want to use the console transport, which prints emails to stdout:
[]
= "console"
Sending Emails
You can access the email sender by using the Email extractor.
use ;
use ;
use ;
async
Email Message Builder
The EmailMessage::builder() provides a fluent interface to construct emails. It supports:
- From/To/Cc/Bcc: Set recipients and sender.
- Subject: Set the email subject.
- Body: Set the plain text body.
- Html: Set the HTML body (if supported).
- Attachments: Add file attachments.
See the API reference for more details.