Send emails with VS Code and Mailtrap

With the VS Code Mailtrap integration, you can now send emails from VS Code with simple prompts.

Mailtrap is an email-sending solution for developer and product teams. Focused on fast delivery and high inboxing rates for transactional and promo emails. Provides highly customizable API and 24/7 tech support.

In this article, you’ll learn how to set it all up and start sending emails in three steps.

Prerequisites: 

  • If you haven’t set up your sending domain already, you’ll need to do it before we start—it takes ~5 minutes, and you can use our step-by-step article as a guide.
  • Install the latest Node.js version since Mailtrap MCP is implemented as a Node.js command line utility.
  • If you haven’t already done so, install Visual Studio Code. But if you have, make sure it’s updated and uses the latest version.

Step 1. Add Mailtrap MCP to VS Code

To add Mailtrap MCP to VS Code, you can use the quick install link or open your VS Code editor, navigate to Settings, and find the Mcp tab via the search bar.

Tick the Chat> Mcp: Enabled option and click on Edit in settings.json since this should open the settings.json config file.

Pro tip: You can also open the settings.json file by typing the following in the Command Pallette: Preferences: Open User Settings (JSON).

Then, in the settings.json file, copy/paste the following code snippet:

{
  "mcp": {
    "servers": {
      "mailtrap": {
        "command": "npx",
        "args": ["-y", "mcp-mailtrap"],
        "env": {
          "MAILTRAP_API_TOKEN": "your_mailtrap_api_token",
          "DEFAULT_FROM_EMAIL": "your_sender@example.com"
        }
      }
    }
  }
}

Important: Make sure to restart your MCP server after changing the “env” section.

Step 2. Add Mailtrap API credentials

All there’s left to do is replace the following values in the settings.json file:

  • MAILTRAP_API_TOKEN – Used to authenticate API requests, which you can copy/paste from the credentials tab.
  • DEFAULT_FROM_EMAIL – Make sure the email’s domain matches your own domain from the Sending Domains tab in Mailtrap.

You can find these credentials in your Mailtrap account by navigating to Sending Domains → Integration → API.

Note: Although you shouldn’t face any issues, I still recommend reloading VS Code to make sure everything is being set up correctly.

Step 3. Send emails with a prompt

To send an email, open the AI Pane of the VS Code editor in the upper-right corner. Then, in the opened pane, make sure Agent mode is selected, which allows VS Code to perform actions for us.

Next, open the list of available tools and select Mailtrap. If you see similar MCPs from other code editors (for instance, Cursor), make sure to uncheck them.

Finally, to send a plain-text email, use the prompt below, but feel free to come up with your own prompts and experiment since the possibilities are plenty. 🙂

Send an email to john.doe@example.com with the subject ‘Hi John!’ and a message that wishes John a great day.

VS Code will then identify the right MCP server for your request, and suggest running the right tool in this case, send-email. 

As soon as you’re ready, click Continue.

The plain-text email should be sent successfully, and the VS Code Copilot AI will notify you about. 

You can verify it by checking the Email Logs tab of your Mailtrap dashboard.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us