API Integration
Integrate Mailtrap email API. Get API credentials, choose transactional or bulk sending, use SDKs or code samples, and start sending.
For use with AI assistants
AI-readable resources:
This page as Markdown — https://docs.mailtrap.io/email-api-smtp/setup/api-integration.md
API reference as Markdown — https://docs.mailtrap.io/developers/email-sending/transactional.md, https://docs.mailtrap.io/developers/email-sending/bulk.md
llms.txt — https://docs.mailtrap.io/llms.txt
llms-full.txt — https://docs.mailtrap.io/llms-full.txt
SDK repos: .NET — https://github.com/mailtrap/mailtrap-dotnet Elixir — https://github.com/mailtrap/mailtrap-elixir Java — https://github.com/mailtrap/mailtrap-java Node.js — https://github.com/mailtrap/mailtrap-nodejs PHP — https://github.com/mailtrap/mailtrap-php Python — https://github.com/mailtrap/mailtrap-python Ruby — https://github.com/mailtrap/mailtrap-ruby
For setup with AI assistant follow these steps. Pause and confirm with the user before proceeding at steps marked with ⏸️.
⏸️ Ask the user for their tech stack (language/framework) and whether they need transactional emails, bulk emails, or both.
⏸️ Ask the user for their API token, verified sending domain, and "from" email address (must be on the verified domain, e.g. hello@yourdomain.com). If they don't have a token or domain yet, direct them to API Tokens setup (https://docs.mailtrap.io/email-api-smtp/setup/api-tokens.md) and Sending Domain setup (https://docs.mailtrap.io/email-api-smtp/setup/sending-domain.md).
Install the appropriate SDK if one is available for the user's stack. Refer to the matching SDK repo above for installation instructions.
Generate sending code using the Transactional Stream endpoint (POST https://send.api.mailtrap.io/api/send) or Bulk Stream endpoint (POST https://bulk.api.mailtrap.io/api/send) depending on the user's choice in step 1.
⏸️ Send a test email to verify the integration works. Confirm the recipient address with the user before sending.
Check that the email appears in the recipient's inbox and in Mailtrap Email Logs (https://mailtrap.io/api-smtp/email-logs).
My tech stack: [tell the assistant your language/framework]
My API token: [paste your token here — only share in a private AI assistant session]
My sending domain: [your verified domain]
My "from" address: [e.g. hello@yourdomain.com]
Transactional or bulk: [tell the assistant which stream you need]
Use API credentials to integrate Mailtrap with your project.
Go to the Sending Setup page under API/SMTP and choose the domain you want to send emails from. Remember that you'll be able to start sending emails once the domain is verified.
Select whether you want to send emails with the Transactional or Bulk Stream.
Transactional Stream is used to send automated, non-promotional application emails triggered by a specific user action. Bulk Stream is used to send a single marketing campaign to a large group of recipients in bulk. Toggle the switch to API.
Toggle the switch to API.
Build the authenticated HTTP request in your programming language or framework and configure it with Mailtrap Host and API Token.
Alternatively, choose the programming language or framework from the menu under Code Samples and copy the sample configuration (it will already contain your credentials). In this menu, you'll find official SDKs for PHP, Python, Ruby, and Node.js.
For now, only Ruby, PHP (Laravel + Symfony), and Node.js SDKs support Bulk Stream, but others are in development. Request and response examples are also available here.
Verifying your configuration
Once you add Mailtrap Email API to your project, try sending an email from the tool of your choice or the project you're working on. If you did everything correctly, you should find the sent email in the inbox of the email address you specified in the script. The email will also appear in the Mailtrap Email Logs.

API tokens
Remember that each domain has different API tokens. You can also create additional API tokens by going to Settings → API Tokens and clicking Add Token.

Mailtrap Email Sending API supports:
attachments
If you need any help with API integration, please, contact our support team at support@mailtrap.io.
Last updated
Was this helpful?

