This project consists of a Go-based service for sending emails using an HTTP endpoint and RabbitMQ for message queuing. The service reads from a RabbitMQ queue and sends emails using the specified SMTP server. The service ensures reliable message processing, including retry mechanisms and persistence in the event of crashes.
- HTTP API to receive email data and queue it for processing.
- Uses RabbitMQ for message queuing to handle email sending asynchronously.
- SMTP integration to send emails.
- Retry logic for failed email deliveries.
- Error logging for troubleshooting.
- Go installed on your device or use Docker.
- A running RabbitMQ instance.
- An SMTP server for sending emails.
- Clone the Repository:
git clone https://github.com/qnton/bulker
cd email-service
- Set Up Environment Variables:
Create a .env
file in the root directory of the project and set the following environment variables:
RABBITMQ_HOST=rabbitmq
RABBITMQ_PORT=5672
RABBITMQ_USER=guest
RABBITMQ_PASS=guest
SMTP_SERVER=email-smtp.eu-central-1.amazonaws.com
SMTP_PORT=465
SMTP_USER=user
SMTP_PASS=pass
SMTP_FROM=test@example.com
AUTH_KEY=qwerty
- Example Docker Compose Setup
Create a docker-compose.yml
file with the following content:
services:
rabbitmq:
image: rabbitmq:latest
ports:
- "5672:5672"
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
app:
build: .
ports:
- "8080:8080"
depends_on:
- rabbitmq
env_file:
- .env
restart: always
- Build and Run the Services:
Ensure Docker and Docker Compose are installed, then use the following command to build and start the services:
docker-compose up --build
The service exposes an HTTP POST endpoint at http://localhost:8080/send-mail
to receive email data and queue it for processing.
curl -X POST \
http://localhost:8080/send-mail \
-H 'Content-Type: application/json' \
-H 'Authorization: qwerty' \
-d '{
"recipient_list": [
{"name": "Max", "to": "email1@example.com"},
{"name": "Mustermann", "to": "email2@example.com"}
],
"subject": "Hello {{.name}}",
"content": "<p>Hello <b>{{.name}}</b></p>"
}'
This project is licensed under the MIT License - see the LICENSE file for details.