https://github.com/harr1424/relay-mailer
An Actix Web server leveraging the lettre crate to relay form field data to email addresses
https://github.com/harr1424/relay-mailer
actix-web lettre rust
Last synced: 4 months ago
JSON representation
An Actix Web server leveraging the lettre crate to relay form field data to email addresses
- Host: GitHub
- URL: https://github.com/harr1424/relay-mailer
- Owner: harr1424
- Created: 2024-10-06T01:58:44.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-15T13:28:10.000Z (4 months ago)
- Last Synced: 2025-06-15T14:56:23.668Z (4 months ago)
- Topics: actix-web, lettre, rust
- Language: Rust
- Homepage: https://crates.io/crates/relay-mailer
- Size: 121 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## relay-mailer
An Actix Web server leveraging the [lettre](https://docs.rs/lettre/latest/lettre/) crate to receive, validate, and sanitize form field data and relay it to an email server.
## Setup
It is necessary to provide a `Config.toml` file containing the following:
- user: a string describing the username for the relay server
- pwd: a string describing the password for the relay server (this will usually be an app password similar to an API key)
- forward_address: a string describing the email address to forward messages to
- server: a string describing the server URL matching the username and pwd
- listen_address: a string describing the address and port the server will listen on## Example Config.toml file that matches this schema
```toml
user = "bob@mail.com"
pwd = "04 08 0F 10 17 2A"
forward_address = "alice@mail.com"
server = "smtp.mail.com"
listen_address = "0.0.0.0:8080"
```## The form data expected by the server is as follows:
- name: a string describing the contact's name with a minimum length of 1 and a maximum length of 30
- country: a string describing the contact's country with a minimum length of 1 and a maximum length of 30
- email: a string describing the contact's email address that must be a valid email
- message: a string representation of the contact's message with a minimum length of 1
- language: an optional string describing the contact's preferred language## The server is rate limited to four requests per 24 hours by default
```rust
#[actix_web::main]
pub async fn main() -> std::io::Result<()> {
env_logger::builder().filter_level(LevelFilter::Info).init();let config = Config::load_from_file("Config.toml").expect("Failed to load configuration file Config.toml");
let config_arc = Arc::new(config.clone());let limiter = LimiterBuilder::new()
.with_duration(Duration::days(1))
.with_num_requests(4)
.build();HttpServer::new(move || {
App::new()
.app_data(Data::new(config_arc.clone()))
.wrap(Logger::default())
.wrap(RateLimiter::new(Arc::clone(&limiter)))
.wrap(DefaultHeaders::new().add(("X-Content-Type-Options", "nosniff")))
.wrap(DefaultHeaders::new().add(("X-Robots-Tag", "noindex, nofollow")))
.service(relay_message)
})
.bind(&config.listen_address)?
.run()
.await
}
```