This example shows how to send transactional emails using Mailtrap's Email API with Encore.
- A Mailtrap account
- A verified sending domain
- A Mailtrap API token from API settings
- Clone and install the example:
encore app create my-app --example=mailtrap-email
cd my-app- Set your Mailtrap API token as an Encore secret:
encore secret set --type local,dev,prod MailtrapAPIToken- Run the app locally:
encore runCall the API endpoint to send an email:
curl -X POST http://localhost:4000/email/send \
-H "Content-Type: application/json" \
-d '{
"to": "recipient@example.com",
"subject": "Hello from Encore + Mailtrap",
"body": "This email was sent using Mailtrap Email API and Encore."
}'To test emails safely without delivering to real inboxes, use Mailtrap's Sandbox API by setting the MAILTRAP_SANDBOX environment variable to true and providing your MAILTRAP_INBOX_ID.