GraphQL Email API Tutorial

Discover the Power of GraphQL with MailSlurp's Email API- Send and receive emails through GraphQL. Check out the free email address API endpoint now!

  • Table of contents

GraphQL is a hot new technology for fetching data using a graph. MailSlurp offers a free email address API that you can use to create inboxes, read email, send emails and more. Let's see how it works.

Where is it?

Access the MailSlurp GraphQL email API endpoint at If you load the url in a browser you'll see the GraphQL explorer. You can use it to perform queries or use your own graphql client locally.

Install GraphQL client

You can install MailSlurp's graphQL library using NPM:

// npm install --save graphql-request
import { gql, GraphQLClient } from 'graphql-request';

Note you will need a free MailSlurp API key. Create an API key at MailSlurp account dashboard and store the value safely. Then use the key in code to configure the client. We must create a client that sets an x-api-key header using your MailSlurp account API KEY.

// create a new graphql-request client using the MailSlurp graphql endpoint
// and passing a headers map including your MailSlurp API Key using "x-api-key" header
const client = new GraphQLClient('', {
  headers: {
    'x-api-key': YOUR_API_KEY,

Making a query

You can make queries like so. Note that the example gql method call should use backticks ` to use template string invocation. Note you can use raw strings without gql too if you prefer.

const query = gql`
    inboxes {
const { inboxes } = await client.request(query);

The great thing about graphql is that you can explore the MailSlurp API schema yourself using the provided GraphQL Playground


Here is how you can perform mutations.

const { createInbox } = await client.request(gql`
  mutation {
    createInbox {

Send email

And here is a way to send emails using GraphQL.

const { sendEmail } = await client.request(
    mutation SendEmail(
      $fromInboxId: String!
      $to: [String!]!
      $subject: String!
    ) {
      sendEmail(fromInboxId: $fromInboxId, to: $to, subject: $subject) {
    to: [createInbox.emailAddress],
    subject: 'Test',

Further reading

For more information please see the GraphQL email guide.

Email and SMS Platform
Create a free account in 3 clicks