Gemini

This guide shows you how to send emails from a verified domain and manage contacts with custom fields and optional List IDs with Gemini 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 Gemini project environment

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

Ready-made prompts for Gemini integration

You can use the following prompts to instruct Gemini 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.

circle-info

Gemini 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 Gemini project

Here we're assuming you already have a Gemini-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 Gemini'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 Gemini-powered environments

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

  • Port access restrictions – Some Gemini 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 Gemini regenerates files to ensure all Mailtrap SDK dependencies are installed.

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

Next steps

  • Use Mailtrap Templates to send branded Gemini-generated emails with variables.

  • Add automation triggers in Mailtrap to send follow-ups to new contacts.

  • Track open and click rates with Mailtrap Email Tracking.

Last updated

Was this helpful?