diff --git a/.env.example b/.env.example index 7b1715c..fb5c90c 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,9 @@ MONGO_URI=mongodb://localhost:27017/txio RUST_LOG=info JWT_SECRET=your_jwt_secret_here BREVO_API_KEY=your_brevo_api_key_here +# Sender for OTP emails. Must be a verified sender/domain in your Brevo account. +EMAIL_FROM=no-reply@txio-backend.com +EMAIL_FROM_NAME=txio Team GROQ_API_KEYS=your_first_groq_key,your_second_groq_key GROQ_MODEL=llama-3.3-70b-versatile PORT=8000 diff --git a/backend/api/src/services/email_service.rs b/backend/api/src/services/email_service.rs index 4959b46..8b0ca87 100644 --- a/backend/api/src/services/email_service.rs +++ b/backend/api/src/services/email_service.rs @@ -17,8 +17,15 @@ impl EmailService { } pub async fn send_otp_email(&self, email: &str, otp: &str) -> Result<(), AppError> { + // Brevo only sends from verified senders, so the from-address must be + // configurable per deployment instead of a hardcoded domain. + let from_email = std::env::var("EMAIL_FROM") + .unwrap_or_else(|_| "no-reply@txio-backend.com".to_string()); + let from_name = + std::env::var("EMAIL_FROM_NAME").unwrap_or_else(|_| "txio Team".to_string()); + let body = json!({ - "sender": { "email": "no-reply@txio-backend.com", "name": "txio Team" }, + "sender": { "email": from_email, "name": from_name }, "to": [{ "email": email }], "subject": "Your txio OTP", "htmlContent": format!("
Your verification code is: {}
This code will expire in 10 minutes.
", otp)