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

  1. In Postman, click New, and then select GraphQL.

    Postman - Create collection

  2. Enter the URL of the SBS endpoint that you want to call (in this example, https://email-api.socrate.io/graphql).

    Postman - Enter URL

  3. On the Authorization tab, select API Key. Set the key name to x-api-key and the key value to the secret key generated previously.

    Postman - Enter URL

    For security purposes, you will likely want to click Set as Variable and store the key value as a variable. In the screen capture below, the variable name is {{SBS_ACCESS_KEY}}.

    Postman - Variable

  4. On the Query tab, click Use GraphQL Introspection. As a result, the GraphQL schema is loaded from the API.

    Postman - Schema

  5. You can now select checkboxes to build your GraphQL queries and add variables. For this tutorial, you can enter the email-sending mutation and variables directly in the upper-right and lower-right text boxes, respectively. The code is included below, for convenience.

    Postman - Query and variables

    mutation sendMessage ($input:SendMessageInput!) {
          sendMessage(
            input: $input
          ) {
            id
            messageId
            from { name address }
            to { name address }
            subject
            textBody
          }
        }
    
    {
          "input": {
          "to": [{ "address": "{{YOUR_EMAIL_ADDRESS}}" }],
            "subject": "Hello from Socrate Business Services!",
            "textBody": "This is a test email"
           }
          }
        
    
  6. Replace {{YOUR_EMAIL_ADDRESS}} as required, and click Query to send the email. If the email was sent successfully, you are presented with a result similar to the one below:

    Postman - Query result

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