The official Go client library for the Elastic Email REST API v4.
Installation β’ Quick start β’ Examples β’ API reference β’ Models β’ Contributing
- Transactional and bulk email. Send single messages, bulk campaigns or CSV merge-file sends.
- Contacts, lists and segments. Add, update, import, export and bulk-delete contacts.
- Campaigns and automations. Create, update, pause and trigger automations for a contact.
- Templates, files and attachments. Manage templates and uploaded files.
- Domains. Verify sending domains and check SPF, DKIM, tracking and certificate status.
- Webhooks and inbound routes. Receive delivery events and route incoming mail.
- Statistics, events and suppressions. Track delivery, bounces, complaints and unsubscribes.
- Subaccounts and security. Manage subaccounts and API keys.
- Idiomatic Go. Every call takes a
context.Context, uses a fluent request builder ending inExecute(), and has no third-party runtime dependencies.
| Platform | Version |
|---|---|
| Go | 1.18 or later, with Go modules |
| Dependencies | None beyond the Go standard library |
You'll also need an Elastic Email API key. You can create one in your API settings. Each endpoint's documentation lists the access level it needs.
Add the github.com/elasticemail/elasticemail-go/v4 module to your project:
go get github.com/elasticemail/elasticemail-go/v4@latestThen import it. The package name is ElasticEmail:
import ElasticEmail "github.com/elasticemail/elasticemail-go/v4"Note
Since 4.2.0 the module path ends in /v4. If you imported github.com/elasticemail/elasticemail-go before, update your imports and run go mod tidy.
Important
Elastic Email only sends from verified domains. Before your first send, verify your sending domain and use an address on that domain as the sender.
package main
import (
"context"
"os"
ElasticEmail "github.com/elasticemail/elasticemail-go/v4"
)
func main() {
client := ElasticEmail.NewAPIClient(ElasticEmail.NewConfiguration())
ctx := context.WithValue(context.Background(), ElasticEmail.ContextAPIKeys,
map[string]ElasticEmail.APIKey{
"apikey": {Key: os.Getenv("ELASTICEMAIL_API_KEY")},
})
// use client and ctx, see below
}The API key travels in the request context, so pass that ctx to every call.
Tip
Keep your API key out of source code. Load it from an environment variable or a secrets manager.
html := ElasticEmail.NewBodyPart(ElasticEmail.BODYCONTENTTYPE_HTML)
html.SetContent("<h1>Hello!</h1><p>Thanks for signing up.</p>")
text := ElasticEmail.NewBodyPart(ElasticEmail.BODYCONTENTTYPE_PLAIN_TEXT)
text.SetContent("Hello! Thanks for signing up.")
content := ElasticEmail.NewEmailContent("My App <no-reply@yourdomain.com>")
content.SetSubject("Welcome aboard!")
content.SetBody([]ElasticEmail.BodyPart{*html, *text})
recipients := ElasticEmail.NewTransactionalRecipient([]string{"john.doe@example.com"})
message := ElasticEmail.NewEmailTransactionalMessageData(*recipients, *content)
result, httpRes, err := client.EmailsAPI.EmailsTransactionalPost(ctx).
EmailTransactionalMessageData(*message).
Execute()
if err != nil {
var apiErr *ElasticEmail.GenericOpenAPIError
if errors.As(err, &apiErr) && httpRes != nil {
log.Fatalf("Elastic Email API error %d: %s", httpRes.StatusCode, apiErr.Body())
}
log.Fatal(err)
}
fmt.Printf("Sent. TransactionID: %s, MessageID: %s\n", result.GetTransactionID(), result.GetMessageID())The from address must use a domain you've verified in your Elastic Email account.
content := ElasticEmail.NewEmailContent("My App <no-reply@yourdomain.com>")
content.SetTemplateName("welcome-template")
content.SetMerge(map[string]string{"firstname": "John"})
recipients := ElasticEmail.NewTransactionalRecipient([]string{"john.doe@example.com"})
message := ElasticEmail.NewEmailTransactionalMessageData(*recipients, *content)
_, _, err := client.EmailsAPI.EmailsTransactionalPost(ctx).
EmailTransactionalMessageData(*message).
Execute()Configuration.HTTPClient accepts any *http.Client, so you can set timeouts, a proxy or your own transport:
proxyURL, _ := url.Parse("http://myProxyUrl:80/")
cfg := ElasticEmail.NewConfiguration()
cfg.HTTPClient = &http.Client{
Timeout: 30 * time.Second,
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
}
client := ElasticEmail.NewAPIClient(cfg)The default client (http.DefaultClient) also honours the HTTP_PROXY and HTTPS_PROXY environment variables.
Optional model fields are pointers. Use the setters (SetSubject, SetMerge, β¦) or the Ptr* helpers (PtrString, PtrInt32, PtrBool, PtrTime, β¦) to build values inline, and the Get* accessors to read them without nil checks.
More complete, runnable samples are in the Elastic Email examples repository. It covers transactional email, SMTP, webhooks, inbound email, contacts and serverless platforms across 20+ languages and frameworks.
- πΉ Go examples (plain
net/http, Chi and Gin) - π All examples
| Scheme | Header | Used for |
|---|---|---|
apikey |
X-ElasticEmail-ApiKey |
All standard API calls |
ApiKeyAuthCustomBranding |
X-Auth-Token |
Custom-branding (white-label) accounts |
Both are passed as entries in the map[string]ElasticEmail.APIKey stored under ElasticEmail.ContextAPIKeys, keyed by the scheme name.
- Up to 20 concurrent connections per account
- A hard timeout of 600 seconds per request
All URIs are relative to https://api.elasticemail.com/v4. The SDK covers 114 endpoints across 16 API services, exposed as fields on APIClient: CampaignsAPI, ContactsAPI, DomainsAPI, EmailsAPI, EventsAPI, FilesAPI, InboundRouteAPI, ListsAPI, SecurityAPI, SegmentsAPI, StatisticsAPI, SubAccountsAPI, SuppressionsAPI, TemplatesAPI, VerificationsAPI and WebhookAPI.
Show all endpoints
All URIs are relative to https://api.elasticemail.com/v4
| Class | Method | HTTP request | Description |
|---|---|---|---|
| CampaignsAPI | CampaignsAutomationByNameTriggerPost | Post /campaigns/automation/{name}/trigger | Trigger Automation for Contact |
| CampaignsAPI | CampaignsByNameDelete | Delete /campaigns/{name} | Delete Campaign |
| CampaignsAPI | CampaignsByNameGet | Get /campaigns/{name} | Load Campaign |
| CampaignsAPI | CampaignsByNamePausePut | Put /campaigns/{name}/pause | Pause Campaign |
| CampaignsAPI | CampaignsByNamePut | Put /campaigns/{name} | Update Campaign |
| CampaignsAPI | CampaignsGet | Get /campaigns | Load Campaigns |
| CampaignsAPI | CampaignsPost | Post /campaigns | Add Campaign |
| ContactsAPI | ContactsByEmailDelete | Delete /contacts/{email} | Delete Contact |
| ContactsAPI | ContactsByEmailGet | Get /contacts/{email} | Load Contact |
| ContactsAPI | ContactsByEmailPut | Put /contacts/{email} | Update Contact |
| ContactsAPI | ContactsDeletePost | Post /contacts/delete | Delete Contacts Bulk |
| ContactsAPI | ContactsExportByIdStatusGet | Get /contacts/export/{id}/status | Check Export Status |
| ContactsAPI | ContactsExportPost | Post /contacts/export | Export Contacts |
| ContactsAPI | ContactsGet | Get /contacts | Load Contacts |
| ContactsAPI | ContactsImportPost | Post /contacts/import | Upload Contacts |
| ContactsAPI | ContactsPost | Post /contacts | Add Contact |
| DomainsAPI | DomainsByDomainDelete | Delete /domains/{domain} | Delete Domain |
| DomainsAPI | DomainsByDomainGet | Get /domains/{domain} | Load Domain |
| DomainsAPI | DomainsByDomainPut | Put /domains/{domain} | Update Domain |
| DomainsAPI | DomainsByDomainRestrictedGet | Get /domains/{domain}/restricted | Check for domain restriction |
| DomainsAPI | DomainsByDomainVerificationPut | Put /domains/{domain}/verification | Verify Domain |
| DomainsAPI | DomainsByEmailDefaultPatch | Patch /domains/{email}/default | Set Default |
| DomainsAPI | DomainsGet | Get /domains | Load Domains |
| DomainsAPI | DomainsPost | Post /domains | Add Domain |
| EmailsAPI | EmailsByMsgidViewGet | Get /emails/{msgid}/view | View Email |
| EmailsAPI | EmailsByTransactionidStatusGet | Get /emails/{transactionid}/status | Get Status |
| EmailsAPI | EmailsMergefilePost | Post /emails/mergefile | Send Bulk Emails CSV |
| EmailsAPI | EmailsPost | Post /emails | Send Bulk Emails |
| EmailsAPI | EmailsTransactionalPost | Post /emails/transactional | Send Transactional Email |
| EventsAPI | EventsByTransactionidGet | Get /events/{transactionid} | Load Email Events |
| EventsAPI | EventsChannelsByNameExportPost | Post /events/channels/{name}/export | Export Channel Events |
| EventsAPI | EventsChannelsByNameGet | Get /events/channels/{name} | Load Channel Events |
| EventsAPI | EventsChannelsExportByIdStatusGet | Get /events/channels/export/{id}/status | Check Channel Export Status |
| EventsAPI | EventsExportByIdStatusGet | Get /events/export/{id}/status | Check Export Status |
| EventsAPI | EventsExportPost | Post /events/export | Export Events |
| EventsAPI | EventsGet | Get /events | Load Events |
| FilesAPI | FilesByNameDelete | Delete /files/{name} | Delete File |
| FilesAPI | FilesByNameGet | Get /files/{name} | Download File |
| FilesAPI | FilesByNameInfoGet | Get /files/{name}/info | Load File Details |
| FilesAPI | FilesGet | Get /files | List Files |
| FilesAPI | FilesPost | Post /files | Upload File |
| InboundRouteAPI | InboundrouteByIdDelete | Delete /inboundroute/{id} | Delete Route |
| InboundRouteAPI | InboundrouteByIdGet | Get /inboundroute/{id} | Get Route |
| InboundRouteAPI | InboundrouteByIdPut | Put /inboundroute/{id} | Update Route |
| InboundRouteAPI | InboundrouteGet | Get /inboundroute | Get Routes |
| InboundRouteAPI | InboundrouteOrderPut | Put /inboundroute/order | Update Sorting |
| InboundRouteAPI | InboundroutePost | Post /inboundroute | Create Route |
| ListsAPI | ListsByListnameContactsGet | Get /lists/{listname}/contacts | Load Contacts in List |
| ListsAPI | ListsByNameContactsPost | Post /lists/{name}/contacts | Add Contacts to List |
| ListsAPI | ListsByNameContactsRemovePost | Post /lists/{name}/contacts/remove | Remove Contacts from List |
| ListsAPI | ListsByNameDelete | Delete /lists/{name} | Delete List |
| ListsAPI | ListsByNameGet | Get /lists/{name} | Load List |
| ListsAPI | ListsByNamePut | Put /lists/{name} | Update List |
| ListsAPI | ListsGet | Get /lists | Load Lists |
| ListsAPI | ListsPost | Post /lists | Add List |
| SecurityAPI | SecurityApikeysByNameDelete | Delete /security/apikeys/{name} | Delete ApiKey |
| SecurityAPI | SecurityApikeysByNameGet | Get /security/apikeys/{name} | Load ApiKey |
| SecurityAPI | SecurityApikeysByNamePut | Put /security/apikeys/{name} | Update ApiKey |
| SecurityAPI | SecurityApikeysGet | Get /security/apikeys | List ApiKeys |
| SecurityAPI | SecurityApikeysPost | Post /security/apikeys | Add ApiKey |
| SecurityAPI | SecuritySmtpByNameDelete | Delete /security/smtp/{name} | Delete SMTP Credential |
| SecurityAPI | SecuritySmtpByNameGet | Get /security/smtp/{name} | Load SMTP Credential |
| SecurityAPI | SecuritySmtpByNamePut | Put /security/smtp/{name} | Update SMTP Credential |
| SecurityAPI | SecuritySmtpGet | Get /security/smtp | List SMTP Credentials |
| SecurityAPI | SecuritySmtpPost | Post /security/smtp | Add SMTP Credential |
| SegmentsAPI | SegmentsByNameDelete | Delete /segments/{name} | Delete Segment |
| SegmentsAPI | SegmentsByNameGet | Get /segments/{name} | Load Segment |
| SegmentsAPI | SegmentsByNamePut | Put /segments/{name} | Update Segment |
| SegmentsAPI | SegmentsGet | Get /segments | Load Segments |
| SegmentsAPI | SegmentsPost | Post /segments | Add Segment |
| StatisticsAPI | StatisticsCampaignsByNameGet | Get /statistics/campaigns/{name} | Load Campaign Stats |
| StatisticsAPI | StatisticsCampaignsGet | Get /statistics/campaigns | Load Campaigns Stats |
| StatisticsAPI | StatisticsChannelsByNameGet | Get /statistics/channels/{name} | Load Channel Stats |
| StatisticsAPI | StatisticsChannelsGet | Get /statistics/channels | Load Channels Stats |
| StatisticsAPI | StatisticsGet | Get /statistics | Load Statistics |
| SubAccountsAPI | SubaccountsByEmailApikeyGet | Get /subaccounts/{email}/apikey | Get SubAccount ApiKey |
| SubAccountsAPI | SubaccountsByEmailCreditsPatch | Patch /subaccounts/{email}/credits | Add, Subtract Email Credits |
| SubAccountsAPI | SubaccountsByEmailDelete | Delete /subaccounts/{email} | Delete SubAccount |
| SubAccountsAPI | SubaccountsByEmailGet | Get /subaccounts/{email} | Load SubAccount |
| SubAccountsAPI | SubaccountsByEmailSettingsEmailPut | Put /subaccounts/{email}/settings/email | Update SubAccount Email Settings |
| SubAccountsAPI | SubaccountsGet | Get /subaccounts | Load SubAccounts |
| SubAccountsAPI | SubaccountsPost | Post /subaccounts | Add SubAccount |
| SuppressionsAPI | SuppressionsBouncesGet | Get /suppressions/bounces | Get Bounce List |
| SuppressionsAPI | SuppressionsBouncesImportPost | Post /suppressions/bounces/import | Add Bounces Async |
| SuppressionsAPI | SuppressionsBouncesPost | Post /suppressions/bounces | Add Bounces |
| SuppressionsAPI | SuppressionsByEmailDelete | Delete /suppressions/{email} | Delete Suppression |
| SuppressionsAPI | SuppressionsByEmailGet | Get /suppressions/{email} | Get Suppression |
| SuppressionsAPI | SuppressionsComplaintsGet | Get /suppressions/complaints | Get Complaints List |
| SuppressionsAPI | SuppressionsComplaintsImportPost | Post /suppressions/complaints/import | Add Complaints Async |
| SuppressionsAPI | SuppressionsComplaintsPost | Post /suppressions/complaints | Add Complaints |
| SuppressionsAPI | SuppressionsGet | Get /suppressions | Get Suppressions |
| SuppressionsAPI | SuppressionsUnsubscribesGet | Get /suppressions/unsubscribes | Get Unsubscribes List |
| SuppressionsAPI | SuppressionsUnsubscribesImportPost | Post /suppressions/unsubscribes/import | Add Unsubscribes Async |
| SuppressionsAPI | SuppressionsUnsubscribesPost | Post /suppressions/unsubscribes | Add Unsubscribes |
| TemplatesAPI | TemplatesByNameDelete | Delete /templates/{name} | Delete Template |
| TemplatesAPI | TemplatesByNameGet | Get /templates/{name} | Load Template |
| TemplatesAPI | TemplatesByNamePut | Put /templates/{name} | Update Template |
| TemplatesAPI | TemplatesGet | Get /templates | Load Templates |
| TemplatesAPI | TemplatesPost | Post /templates | Add Template |
| VerificationsAPI | VerificationsByEmailDelete | Delete /verifications/{email} | Delete Email Verification Result |
| VerificationsAPI | VerificationsByEmailGet | Get /verifications/{email} | Get Email Verification Result |
| VerificationsAPI | VerificationsByEmailPost | Post /verifications/{email} | Verify Email |
| VerificationsAPI | VerificationsFilesByIdDelete | Delete /verifications/files/{id} | Delete File Verification Result |
| VerificationsAPI | VerificationsFilesByIdResultDownloadGet | Get /verifications/files/{id}/result/download | Download File Verification Result |
| VerificationsAPI | VerificationsFilesByIdResultGet | Get /verifications/files/{id}/result | Get Detailed File Verification Result |
| VerificationsAPI | VerificationsFilesByIdVerificationPost | Post /verifications/files/{id}/verification | Start verification |
| VerificationsAPI | VerificationsFilesPost | Post /verifications/files | Upload File with Emails |
| VerificationsAPI | VerificationsFilesResultGet | Get /verifications/files/result | Get Files Verification Results |
| VerificationsAPI | VerificationsGet | Get /verifications | Get Emails Verification Results |
| WebhookAPI | WebhookByPublicidDelete | Delete /webhook/{publicid} | Delete Webhook |
| WebhookAPI | WebhookByPublicidGet | Get /webhook/{publicid} | Load Webhook |
| WebhookAPI | WebhookByPublicidPut | Put /webhook/{publicid} | Update Webhook |
| WebhookAPI | WebhookGet | Get /webhook | Load Webhooks |
| WebhookAPI | WebhookPost | Post /webhook | Add Webhook |
Show all 98 models
- AccessLevel
- AccountStatusEnum
- ApiKey
- ApiKeyPayload
- BodyContentType
- BodyPart
- Campaign
- CampaignOptions
- CampaignRecipient
- CampaignStatus
- CampaignTemplate
- CertificateValidationStatus
- ChannelLogStatusSummary
- CompressionFormat
- ConsentData
- ConsentTracking
- Contact
- ContactActivity
- ContactPayload
- ContactSource
- ContactStatus
- ContactUpdatePayload
- ContactsList
- DKIMRecord
- DeliveryOptimizationType
- DomainData
- DomainDetail
- DomainOwner
- DomainPayload
- DomainUpdatePayload
- EmailContent
- EmailData
- EmailJobFailedStatus
- EmailJobStatus
- EmailMessageData
- EmailPredictedValidationStatus
- EmailRecipient
- EmailSend
- EmailStatus
- EmailTransactionalMessageData
- EmailValidationResult
- EmailValidationStatus
- EmailView
- EmailsPayload
- EncodingType
- EventType
- EventsOrderBy
- ExportFileFormats
- ExportLink
- ExportStatus
- FileInfo
- FilePayload
- FileUploadResult
- InboundPayload
- InboundRoute
- InboundRouteActionType
- InboundRouteFilterType
- ListPayload
- ListUpdatePayload
- LogJobStatus
- LogStatusSummary
- MergeEmailPayload
- MessageAttachment
- MessageCategory
- MessageCategoryEnum
- NewApiKey
- NewSmtpCredentials
- Options
- RecipientEvent
- Segment
- SegmentPayload
- SmtpCredentials
- SmtpCredentialsPayload
- SortOrderItem
- SplitOptimizationType
- SplitOptions
- SubAccountInfo
- SubaccountEmailCreditsPayload
- SubaccountEmailSettings
- SubaccountEmailSettingsPayload
- SubaccountPayload
- SubaccountSettingsInfo
- SubaccountSettingsInfoPayload
- Suppression
- Template
- TemplatePayload
- TemplateScope
- TemplateType
- TrackingType
- TrackingValidationStatus
- TransactionalRecipient
- Utm
- VerificationFileResult
- VerificationFileResultDetails
- VerificationStatus
- Webhook
- WebhookCreatePayload
- WebhookUpdatePayload
The SDK follows the Elastic Email API v4 and uses semantic import versioning, so the major version is part of the module path (/v4). Available versions are listed on pkg.go.dev and in GitHub Releases.
Build details
- API version: 4.0.0
- SDK version: 4.2.0
- Generator version: 7.11.0
- Build package:
org.openapitools.codegen.languages.GoClientCodegen
Contributions are welcome! Most of this SDK is generated from the OpenAPI specification, so please read CONTRIBUTING.md before opening a pull request.
- π Report a bug
- π‘ Request a feature
- π Report a security issue
This project follows the Contributor Covenant Code of Conduct.
Important
The fastest way to get help is the chat widget on elasticemail.com. Our support team can help with your account, sending, deliverability and API questions.
- π¬ Chat with support on elasticemail.com (preferred)
- π API documentation
- π§ͺ Examples repository
- π GitHub issues, for bugs in this SDK only
Released under the MIT License. Copyright Β© 2021β2026 Elastic Email.