ChatGPT

This guide shows you how to send emails from a verified domain and manage contacts with custom fields and optional List IDs with ChatGPT and Mailtrap Email API.

Prerequisites

Before you start, make sure you have:

  • Verified sending domain in Mailtrap

  • Admin API token with access to your domain, Contacts, and Production Email API

  • Account ID (Go to Settings, then Account Settings in Mailtrap dashboard)

  • Optional List IDs if you want to store contacts in specific lists

  • Custom fields created in Mailtrap if you want to store extra metadata

  • Node.js or Python installed in your GPT project environment

  • Ability to set environment variables in your GPT hosting setup (via .env files or runtime configuration)

Ready-made prompts for GPT integration

You can use the following prompts to instruct GPT to integrate the service for you.

Email sending

Prompt

Create a Node.js app that uses the Mailtrap SDK to send an email via the Email API from a verified domain. Store credentials in environment variables.

Email sending + HTML template

Prompt

Generate a Python script using the Mailtrap SDK that sends a production email with HTML content and template variables.

Full integration

Prompt

Build a Node.js app that sends a production email, then creates or updates a contact in Mailtrap Contacts with custom fields and optional List ID.

ChatGPT provides you with accurate, safe flows, and the code. However, it uses placeholders for credentials, and they need to be added in manually. And you need a proper IDE to test, run, and deploy your project.

Step-by-step setup guide

1

Prepare Mailtrap

  1. Verify your sending domain in Mailtrap.

  2. Create an Admin API token with production_send and contacts_write scopes.

  3. Locate your Account ID in Settings > Account Settings.

  4. (Optional) Create Lists if you plan to organize contacts.

  5. (Optional) Create Custom Fields for storing metadata like plan or signup_source.

2

Create/open your GPT project

Here we're assuming you already have a GPT-powered project within an IDE like Cursor or Replit. If so, simply open the project.

For manual setup:

3

Send emails with Node.js and Python

4

Create/update a contact in Mailtrap

5

Run and verify

  1. Set your environment variables in GPT's environment:

  1. Run the script:

  1. Check the recipient inbox to ensure the email landed where it's supposed to.

  2. Go to Mailtrap Contacts to verify new or updated contact.

Troubleshooting GPT-powered environments

  • Environment variables not loading – GPT environments may require .env loading via dotenv in Node.js or python-dotenv in Python.

  • Port access restrictions – Some GPT hosting providers block SMTP - so use only HTTPS Email API as explained in this article.

  • Missing dependencies – Always run npm install or pip install after GPT regenerates files to ensure all Mailtrap SDK dependencies are installed.

  • CORS or cross-domain errors – If calling Mailtrap from a GPT web client, route requests through your backend to keep API token secure.

Next steps

Last updated

Was this helpful?