Setup a Webhook

Step 1: Create your endpoint

Firstly, you need to create a URL endpoint in your application that can receive the webhook data by an HTTP or HTTPS POST request generated from SMTP2GO. The required URL format and further details including optionally securing your URL with a username/password are covered in the Webhooks Overview article.

Step 2: Setup the webhook in your account

Secondly, you will need to create the webhook in your account which can be done in the SMTP2GO App or by using the API.

Setup in the App

In the App, navigate to the "Settings > Webhooks" section.

Click the "Add Webhook" button and define the webhook:

  • Add your endpoint URL where the POST request will be delivered.
  • Set which Users the webhook will trigger for - you can individually select SMTP Users, API Keys or Authenticated IPs (IP Authentication - available on paid plans).
  • Select the events the webhook will provide data on (e.g. Bounce, Open, Click etc.).
  • Optionally add custom headers.

You can use the "Test" button to test the webhook and once ready click "Save".

Setup using the API

The webhook/add endpoint can be used to add a webhook programmatically. View the Add a new Webhook API reference page to see the accepted parameters, code examples and test.
Using the API you can additionally view, edit and remove webhooks.

Below is a cURL example of adding a new webhook that will trigger immediately when an open, bounce or click event occurs for sending through the defined API Key and an SMTP User (username).

curl --request POST \
     --url https://api.smtp2go.com/v3/webhook/add \
     --header 'Content-Type: application/json' \
     --header 'X-Smtp2go-Api-Key: api-*********APIKey**************' \
     --header 'accept: application/json' \
     --data '
{
  "events": [
    "open",
    "click",
    "bounce"
  ],
  "usernames": [
    "api-*********APIKey**************",
    "Usernametest123"
  ],
  "url": "https//webhook.example.com/webhook12345"
}
'

Step 3: Receive webhook requests

Finally, with your webhook set up, you'll begin to receive the POST requests automatically to your URL endpoint when your webhook events occur. The event data will be application/x-www-form-urlencoded in the body. If you would prefer the webhook request in JSON, please contact our support team who can have that enabled for the particular webhook. Upon receiving the webhook event requests, your application can parse the data and take action based on the event.