# GitHub Copilot

[GitHub Copilot](https://github.com/features/copilot) is an AI coding assistant that works inside VS Code, JetBrains IDEs, Eclipse, Xcode, and Visual Studio. In this guide, you’ll learn how to connect it with the Mailtrap MCP server, which allows you to, amongst other things, perform the following actions:

* [Connect Mailtrap to your project](#connect-mailtrap-to-your-project)
* [Perform Sandbox operations during code review](#sandbox-operations-during-code-review)
* [Fetch, validate, and edit email templates](#template-validation)
* [Forward email templates to your teammates](#sending-emails-to-your-teammate)

#### Prerequisites

Before you start, make sure to:

* Set up your [sending domain](https://docs.mailtrap.io/email-api-smtp/setup/sending-domain) (this takes approximately 5 minutes).
* Install the latest Node.js version since [Mailtrap MCP](https://www.npmjs.com/package/mcp-mailtrap) is implemented as a Node.js command line utility.
* Update VS Code to the latest version with GitHub Copilot enabled.

### Step 1. Add Mailtrap MCP config to GitHub Copilot

To add Mailtrap MCP to GitHub Copilot in VS Code, you can use the [quick install link](https://insiders.vscode.dev/redirect/mcp/install?name=mailtrap\&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22mcp-mailtrap%22%5D%2C%22env%22%3A%7B%22MAILTRAP_API_TOKEN%22%3A%22%24%7Binput%3AmailtrapApiToken%7D%22%2C%22DEFAULT_FROM_EMAIL%22%3A%22%24%7Binput%3AsenderEmail%7D%22%2C%22MAILTRAP_ACCOUNT_ID%22%3A%22%24%7Binput%3AmailtrapAccountId%7D%22%7D%7D\&inputs=%5B%7B%22type%22%3A%22promptString%22%2C%22id%22%3A%22mailtrapApiToken%22%2C%22description%22%3A%22Mailtrap+API+Token%22%2C%22password%22%3Atrue%7D%2C%7B%22type%22%3A%22promptString%22%2C%22id%22%3A%22senderEmail%22%2C%22description%22%3A%22Sender+Email+Address%22%7D%2C%7B%22type%22%3A%22promptString%22%2C%22id%22%3A%22mailtrapAccountId%22%2C%22description%22%3A%22Mailtrap+Account+ID%22%7D%5D) or follow these steps:

* Open VS Code and navigate to **Settings**
* Search for **MCP** in the settings search bar

<figure><img src="https://365478608-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkNigAKiqQtQub1GOdjY%2Fuploads%2FHhh0D5VCTVRRPsklp5aE%2Fcopilot%201.png?alt=media&#x26;token=483fa34f-3cf7-4e8f-98e9-65afa2b9b11c" alt=""><figcaption></figcaption></figure>

* Tick the **Chat > MCP: Enabled** option
* Click **Edit** **in** **settings.json**

{% hint style="info" %}
You can also open the **settings.json** file by typing **Preferences: Open User Settings (JSON)** in the Command Palette.
{% endhint %}

Once you open **settings.json**, insert the following code snippet into the file:

```json
{
  "mcpServers": {
    "mailtrap": {
      "command": "npx",
      "args": ["-y", "mcp-mailtrap"],
      "env": {
        "MAILTRAP_API_TOKEN": "your_mailtrap_api_token",
        "DEFAULT_FROM_EMAIL": "your_sender@example.com",
        "MAILTRAP_ACCOUNT_ID": "your_account_id",
        "MAILTRAP_TEST_INBOX_ID": "your_test_inbox_id"
      }
    }
  }
}
```

### Step 2. Insert Mailtrap credentials

Next, all you need to do is replace the following values in the **settings.json** file:

* `MAILTRAP_API_TOKEN` — Required for all functionality, used to authenticate API requests, which you can copy/paste from the credentials tab.
* `DEFAULT_FROM_EMAIL` — Required for email sending. 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**.

<figure><img src="https://365478608-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkNigAKiqQtQub1GOdjY%2Fuploads%2FjTEOJg78Yz0qkbo7Fj11%2F1.png?alt=media&#x26;token=45eb029d-d0b8-48e8-b4e4-d62ce23d1e80" alt=""><figcaption></figcaption></figure>

* `MAILTRAP_ACCOUNT_ID` — This is required for template management purposes. You can find the account ID under **Settings** → **Account Settings**.

<figure><img src="https://365478608-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkNigAKiqQtQub1GOdjY%2Fuploads%2FmkYoNF7NjSMdHhADqH3L%2F2.png?alt=media&#x26;token=6ddb588e-dba5-46c9-9658-4e02964a213c" alt=""><figcaption></figcaption></figure>

* `MAILTRAP_TEST_INBOX_ID` — If you need sandbox email functionality, you can find this ID in your Sandbox.

<figure><img src="https://365478608-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkNigAKiqQtQub1GOdjY%2Fuploads%2FOz3k5UCZl9mQD4xHP1Ft%2F3.png?alt=media&#x26;token=6a218ba9-4a1e-4a22-acdb-cd6268c32563" alt=""><figcaption></figcaption></figure>

Once you insert your Mailtrap credentials, make sure to refresh the page or reopen VS Code.

{% hint style="info" %}
If you don’t add one or more variables, you’ll be prompted to do it to complete a specific action, and when given the variable, Copilot will ask you to update your **.env** file automatically.
{% endhint %}

### GitHub Copilot + Mailtrap MCP server use cases

#### Connect Mailtrap to your project

Regardless of the IDE you are using Copilot in, you can prompt the agent to integrate Mailtrap into your project with a prompt like this one:

> Integrate Mailtrap into my project, so that it can send emails through the Mailtrap email API.
>
> Additionally, safely store the Mailtrap credentials from the MCP configuration into an .env file

GitHub Copilot’s agent will then go through the Mailtrap documentation, integrate the email API, and safely store your credentials in a **.env** file. Then, you can proceed to test the configuration.

<figure><img src="https://365478608-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkNigAKiqQtQub1GOdjY%2Fuploads%2Fd9jIteRXYwcIhUIbVlu6%2Fcopilot%202.png?alt=media&#x26;token=ae09ce9f-5726-4f9f-ab28-62ed7a46f42a" alt=""><figcaption></figcaption></figure>

#### Sandbox operations during code review

While you’re reviewing your email-sending code and working in a staging environment using [Sandbox](https://mailtrap.io/email-sandbox/), you might want to try to trigger the logic to see if it works correctly or simply to verify the behavior, test emails, etc.

You can do all of this from your IDE connected to GitHub copilot with the following prompts:

<details>

<summary>"Get all messages from my sandbox inbox"</summary>

<figure><img src="https://365478608-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkNigAKiqQtQub1GOdjY%2Fuploads%2FYlxkTZEztqC6awtbzYGV%2Fcopilot%203.png?alt=media&#x26;token=69f47aa5-8733-49c7-9c36-001c38e54b39" alt=""><figcaption></figcaption></figure>

</details>

<details>

<summary>"Show me the first page of sandbox messages"</summary>

<figure><img src="https://365478608-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkNigAKiqQtQub1GOdjY%2Fuploads%2FGYizBiMwdGxH0kXLKdU1%2Fcopilot%204.png?alt=media&#x26;token=67c7e9ad-a986-4f40-9489-d85b1563efce" alt=""><figcaption></figcaption></figure>

</details>

<details>

<summary>"Search for messages containing 'test' in my sandbox inbox"</summary>

<figure><img src="https://365478608-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkNigAKiqQtQub1GOdjY%2Fuploads%2Fp32ewEK5ffsvRxDFbDBy%2Fcopilot%205.png?alt=media&#x26;token=f4422275-5c27-4860-8fb3-b56eccceeb89" alt=""><figcaption></figcaption></figure>

</details>

<details>

<summary>"Show me the details of sandbox message with ID XYZ"</summary>

<figure><img src="https://365478608-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkNigAKiqQtQub1GOdjY%2Fuploads%2FILuSfP1oqf9MrgFI14tE%2Fcopilot%206.png?alt=media&#x26;token=fae95e10-7352-42e2-8e96-45141d7f4c0c" alt=""><figcaption></figcaption></figure>

</details>

#### Template validation

Using a Mailtrap template ID in your code, but you’re not sure whether it’s the correct one? Just request the list of available templates in your Mailtrap account from GitHub Copilot.

<figure><img src="https://365478608-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkNigAKiqQtQub1GOdjY%2Fuploads%2F6NOr9vvlPmARkTJwe5aL%2Fcopilot%207.png?alt=media&#x26;token=e85f1258-4425-4ada-8902-766f041ba333" alt=""><figcaption></figcaption></figure>

#### Sending emails to your teammate

You can also ask your teammates’ opinion on an email design or a template you’re working in your Sandbox by prompting GitHub Copilot, no need to leave the editor.

<figure><img src="https://365478608-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgkNigAKiqQtQub1GOdjY%2Fuploads%2Fi631lfqOfWr7eW1avWvP%2Fcopilot%208.png?alt=media&#x26;token=a3ef43c7-8702-4b88-a8e4-4b54d2e33b28" alt=""><figcaption></figcaption></figure>
