# RUST-SMTP-UTILS
Reusable SMTP helper crate for Rust (lettre-based) with STARTTLS, timeout, and retry.
## Install
` oml
[dependencies]
rust_smtp_utils = { git = "https://github.com/Alexandros5880/RUST-SMTP-UTILS.git" }
`
## Environment
Set these variables:
- SMTP_HOST (default: smtp.gmail.com)
- SMTP_PORT (default: 587)
- SMTP_USERNAME
- SMTP_PASSWORD
## Usage
`
ust
use rust_smtp_utils::{SmtpConfig, send_text_email};
use lettre::message::Mailbox;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = SmtpConfig::from_env()?;
let from = Mailbox::new(Some("My App".into()), config.username.parse()?);
let to = Mailbox::new(None, "admin@example.com".parse()?);
let reply_to = Mailbox::new(None, "user@example.com".parse()?);
send_text_email(
&config,
from,
to,
"Contact form".into(),
"Hello from the website".into(),
Some(reply_to),
)?;
Ok(())
}
`
## Notes
- Uses STARTTLS on port 587.
- Includes a default timeout (10s) and 2 retries with 500ms delay.
- From should be the authenticated SMTP user. Use Reply-To for user addresses.
## Example
Run:
`ash
cargo run --example send
`\n
## License
MIT\n