Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.3 KB

File metadata and controls

50 lines (36 loc) · 1.3 KB

Send Email with Mailtrap

This example shows how to send transactional emails using Mailtrap's Email API with Encore.

Prerequisites

Setup

  1. Clone and install the example:
   encore app create my-app --example=mailtrap-email
   cd my-app
  1. Set your Mailtrap API token as an Encore secret:
   encore secret set --type local,dev,prod MailtrapAPIToken
  1. Run the app locally:
   encore run

Send an email

Call 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."
  }'

Using Mailtrap Sandbox for testing

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.

Learn more