Tutorial: Send an email


This tutorial shows you how to send a simple text email via the Email Service.

Prerequisites

  • You must have a service access key that provides access to the Email Service. More specifically, your service access key’s scope must include the following permissions: email-api:query:* email-api:mutation:*. If you followed the Getting Started chapter, you should already have a service access key with full access to all SBS APIs, including the Email Service. Otherwise, see Generate a service access key.

Send a test email

Once you have a service access key, you can proceed to the GraphQL interface of the Email Service.

  1. Open https://email-api.socrate.io/graphql in your browser.

  2. In the HTTP Headers section at the bottom of the console, enter a value for the x-api-key header, as shown below. This value must be the secret key you have generated previously.

    Populate HTP header

  3. In the GraphQL pane on the left side, run:

mutation sendEmail ($input:SendMessageInput!) {
  sendMessage(
    input: $input
  ) {
    id
  }
}

In the variables, make sure to replace the name and email with your own:

{
  "input": {
      "to": { "name": "Your name", "address": "your.email@example.org" },
      "subject": "Test email",
      "textBody": "Hello from SBS"    
  }
}
  1. Click the Play button.

At this stage, if the email was sent successfully, you are presented with a result similar to the one below:

{
  "data": {
    "sendMessage": {
      "id": "67fe4840-c255-11ed-9f8e-4d21d12d986a"
    }
  }
}

If an error occurred, the result displays an errors object that provides further details about the encountered problem.