Skip to main content

Prerequisites

Before getting started, you’ll need to:
  1. Authorize your sending domain
  2. Create and retrieve your SendLayer API key

Installation

Install the SendLayer Go SDK using the go get command:

Usage

After installation, you can use the SDK modules for sending emails, managing webhooks, and retrieving email events.

Send email in Go

Initialize the client and call sl.Emails.Send() with a SendEmailRequest.
sendEmail.go

Send HTML emails in Go

To send HTML emails, set the Html field in the request payload.
sendEmail.go
You can include both Text and Html to send plain text and HTML versions of the same email.

Send email to multiple recipients

Use EmailAddress objects to send to multiple recipients, including Cc, Bcc, and ReplyTo.
sendEmail.go
From and To accept either a string email or EmailAddress values. Cc, Bcc, and ReplyTo support the same flexible format.
There are limits to the number of email recipients you can add to a single request. See our rate limiting guide to learn more.

Include attachments in email

Include attachments by setting the Attachments field in SendEmailRequest.
sendEmail.go
The maximum email size SendLayer allows is 10MB. This includes both the message as well as attachment files.
Set Path to your local file path or hosted file URL, then set the file Type (MIME type). SendLayer SDK supports both local and remote file attachments and allows you to add multiple attachment files. See our tutorial to learn more about attaching files to emails.

Email request parameters

The table below contains the supported fields in SendEmailRequest.

Manage webhooks in Go

With the SendLayer Go SDK, you can create, list, and delete webhooks.

Create a new webhook

Call Webhooks.Create() with a WebhookCreateRequest.
webhooks.go
The Event field accepts the following values:
  • bounce
  • click
  • open
  • unsubscribe
  • complaint
  • delivery
Example success response for new webhook:

Get all webhooks

To view all the webhooks you’ve created, use the Webhooks.Get() method.
webhooks.go
Example response:

Delete a webhook

To delete a specific webhook, pass the webhook ID to Webhooks.Delete().
Deleting a webhook cannot be undone.
webhooks.go

Webhook request parameters

The table below contains the supported inputs in the Webhooks module.

Retrieve email events

Use the Events module to retrieve email delivery and engagement events.

Get all events

Initialize the client and call Events.Get(nil) to retrieve recent events.
events.go
Example response:

Filter events

Pass a GetEventsRequest to filter by date range and event type.
events.go

Event request parameters

The table below contains supported fields in GetEventsRequest.

Error handling

The SDK returns typed errors you can inspect with errors.As.
Here is an example error response:

More examples

SendLayer Go SDK

View more details and examples on GitHub.