Packaging SMTP(send only) APIs to a choosable option is the goal here, then to have a tiny server that picks 1 provider and serves as HTTP endpoint so the other microservices that belong to you can make email requests.
- Brevo (highly recommended)
- Resend
- Postmark
- Mailchimp
- Mailtrap
- Mailjet
- Mailgun
- Sendgrid (avoid them if you can)
Note: Anything that only uses oauth2 like zoho does will not be implemented here for foreseeable future
export API_KEY=<SECRET_API_KEY>
export PROVIDER=brevo
go run ./cmd/emailer/main.go -debug
Kick the server by after having PROVIDER
and API_KEY
env variables then run go run ./cmd/emailer/main.go
This endpoint allows you to send an email by providing the necessary email details in the request body as JSON.
- Method: POST
- URL: /email
- Request:
-
{ "from": "[email protected]", "to": ["[email protected]", "[email protected]"], "bcc": ["[email protected]", "[email protected]"], "cc": ["[email protected]", "[email protected]"], "subject": "Test Email", "htmlContent": "<p>This is a test email in HTML format.</p>", "textContent": "This is a test email in plain text format." }
-
- Response:
- 200
Email successfully sent
- 400
Encoding error
orFailed to validate
- 500
Failed to send email
(check logs something went wrong with the provider)
- 200
curl -X POST http://localhost:5555/email \
-H "Content-Type: application/json" \
-d '{
"from": "[email protected]",
"to": ["[email protected]"],
"subject": "Test Email",
"htmlContent": "<p>This is a test email in HTML format.</p>",
"textContent": "This is a test email in plain text format."
}'