Skip to main content

Prerequisites

To get the most out of this guide, you’ll need to:

1. Install

Maven users

Add this dependency to your project’s POM:
POM
<dependency>
  <groupId>io.sendpost</groupId>
  <artifactId>sendpost-java-sdk</artifactId>
  <version>1.0.0</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project’s build file:
repositories {
  mavenCentral()  
  mavenLocal()       
}

dependencies {
  implementation "io.sendpost:sendpost-java-sdk:1.0.0"
}

2. Getting Started

Java
import io.sendpost.client.ApiClient;
import io.sendpost.client.ApiException;
import io.sendpost.client.Configuration;
import io.sendpost.client.api.EmailApi;
import io.sendpost.client.model.*;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://api.sendpost.io/api/v1");
    
    EmailApi apiInstance = new EmailApi(defaultClient);
    String xSubAccountApiKey = "your_api_key"; // Sub-Account API Key
    
    EmailMessage emailMessage = new EmailMessage();
    emailMessage.setSubject("Hello World");
    emailMessage.setHtmlBody("<strong>it works!</strong>");
    
    From from = new From();
    from.setEmail("[email protected]");
    emailMessage.setFrom(from);
    
    To to = new To();
    to.setEmail("[email protected]");
    emailMessage.setTo(Arrays.asList(to));

    try {
      List<EmailResponse> result = apiInstance.sendEmail(xSubAccountApiKey, emailMessage);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling EmailApi#sendEmail");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

3. Try it for yourself

Java Example

See detailed sdk example