Skip to content

Latest commit

 

History

History
484 lines (403 loc) · 30.3 KB

File metadata and controls

484 lines (403 loc) · 30.3 KB
Elastic Email

Elastic Email Java SDK

The official Java client library for the Elastic Email REST API v4.

JitPack Java API OpenAPI Generator License: MIT

Latest release Last commit Open issues GitHub stars

Installation • Quick start • Examples • API reference • Models • Contributing


Features

  • 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.
  • Sync and async. Every endpoint has a blocking method, a …WithHttpInfo variant that returns status code and headers, and an …Async method that takes an ApiCallback.

Requirements

Tool Version
Java 8 or later
Maven 3.8.3 or later (or Gradle 7.2 or later)

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.

Installation

The SDK is published on JitPack. Add the JitPack repository and the dependency to your build.

Maven (pom.xml):

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

<dependency>
  <groupId>com.github.ElasticEmail</groupId>
  <artifactId>elasticemail-java</artifactId>
  <version>4.2.0</version>
</dependency>

Gradle (build.gradle):

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.ElasticEmail:elasticemail-java:4.2.0'
}

Maven or Gradle pulls in the dependencies (OkHttp, Gson and gson-fire) for you.

Build from source instead
git clone https://github.com/ElasticEmail/elasticemail-java.git
cd elasticemail-java
mvn clean install

This installs com.elasticemail:elasticemail:4.2.0 to your local Maven repository. To get a single JAR, run mvn clean package and use target/elasticemail-4.2.0.jar together with the JARs in target/lib/.

Quick start

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.

Configure the client

import com.elasticemail.api.EmailsApi;
import com.elasticemail.client.ApiClient;
import com.elasticemail.client.ApiException;
import com.elasticemail.client.Configuration;
import com.elasticemail.client.auth.ApiKeyAuth;
import com.elasticemail.model.*;

ApiClient client = Configuration.getDefaultApiClient();
client.setBasePath("https://api.elasticemail.com/v4");

ApiKeyAuth apikey = (ApiKeyAuth) client.getAuthentication("apikey");
apikey.setApiKey(System.getenv("ELASTICEMAIL_API_KEY"));

Tip

Keep your API key out of source code. Load it from an environment variable, a system property or a secrets manager.

Send a transactional email

EmailsApi emails = new EmailsApi(client);

EmailTransactionalMessageData message = new EmailTransactionalMessageData()
    .recipients(new TransactionalRecipient().addToItem("john.doe@example.com"))
    .content(new EmailContent()
        .from("My App <no-reply@yourdomain.com>")
        .subject("Welcome aboard!")
        .addBodyItem(new BodyPart()
            .contentType(BodyContentType.HTML)
            .content("<h1>Hello!</h1><p>Thanks for signing up.</p>"))
        .addBodyItem(new BodyPart()
            .contentType(BodyContentType.PLAIN_TEXT)
            .content("Hello! Thanks for signing up.")));

try {
    EmailSend result = emails.emailsTransactionalPost(message);
    System.out.println("Sent. TransactionID: " + result.getTransactionID()
        + ", MessageID: " + result.getMessageID());
} catch (ApiException e) {
    System.err.println("Elastic Email API error " + e.getCode() + ": " + e.getResponseBody());
}

The from address must use a domain you've verified in your Elastic Email account.

Send from a template with merge fields

EmailTransactionalMessageData message = new EmailTransactionalMessageData()
    .recipients(new TransactionalRecipient().addToItem("john.doe@example.com"))
    .content(new EmailContent()
        .from("My App <no-reply@yourdomain.com>")
        .templateName("welcome-template")
        .putMergeItem("firstname", "John"));

emails.emailsTransactionalPost(message);

Using a proxy or custom timeouts

The client uses OkHttp. Pass your own OkHttpClient to configure a proxy, timeouts or interceptors:

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;

OkHttpClient http = client.getHttpClient().newBuilder()
    .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("myProxyUrl", 80)))
    .readTimeout(600, TimeUnit.SECONDS)
    .build();
client.setHttpClient(http);

Note

In a multithreaded application, create one ApiClient instance per thread.

More examples

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.

Authentication

Scheme Header Used for
apikey X-ElasticEmail-ApiKey All standard API calls
ApiKeyAuthCustomBranding X-Auth-Token Custom-branding (white-label) accounts

API limits

  • Up to 20 concurrent connections per account
  • A hard timeout of 600 seconds per request

API reference

All URIs are relative to https://api.elasticemail.com/v4. The SDK covers 114 endpoints across 16 API classes: CampaignsApi, ContactsApi, DomainsApi, EmailsApi, EventsApi, FilesApi, InboundRouteApi, ListsApi, SecurityApi, SegmentsApi, StatisticsApi, SubAccountsApi, SuppressionsApi, TemplatesApi, VerificationsApi and WebhookApi.

Show all endpoints
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

Models

Show all 98 models

Tests

The src/test directory holds generated JUnit 5 test stubs for every API class and model. The API tests are marked @Disabled because they call the live API. Run the suite with:

mvn test

Versioning

The SDK follows the Elastic Email API v4. Versions and release notes are listed on JitPack 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.JavaClientCodegen

Contributing

Contributions are welcome! Most of this SDK is generated from the OpenAPI specification, so please read CONTRIBUTING.md before opening a pull request.

This project follows the Contributor Covenant Code of Conduct.

Support

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.

License

Released under the MIT License. Copyright © 2021–2026 Elastic Email.