Home › Projects › Mail Service
API

Mail Service

A lightweight Rust backend for email: it captures newsletter subscribers from the portfolio site into MongoDB. Reached through the Mecca API's notification route.

Rust 2024axum 0.7TokioMongoDBSerde

Overview

Mail Service keeps the email side of the Pi out of the other apps. It has no public hostname; the Mecca API forwards POST /api/notification/subscribe to it and identifies itself with a clientId header.

Endpoints

GET/

Health check — returns a plain-text greeting.

POST/save/subscriber

Store a subscriber. The caller must send a clientId header, which is saved with the record so each app's subscribers stay separate.

Request
clientId: portfolio

{
  "name": "Ada",
  "email": "[email protected]"
}
Response
201 Created   (empty body)
StatusWhen
400clientId header missing
422Body is not {name, email}
500Database write failed

Project layout

src/
├── main.rs                  server, routes, CORS
├── controllers/root.rs      route handlers
├── services/
│   ├── greeting.rs
│   └── database_service.rs  MongoDB access
└── models/subscriber.rs     { name, email, client_id }

Running it

cargo build --release
MONGODB_URI=... ./target/release/mail_service