Back to Docs

Java SDK

Official MailPass SDK for Java

Installation

Add to your pom.xml:

<dependency>
    <groupId>im.mailpass</groupId>
    <artifactId>mailpass-java</artifactId>
    <version>1.0.0</version>
</dependency>

Or with Gradle:

implementation 'im.mailpass:mailpass-java:1.0.0'

Quick Start — OTP Send & Verify

import im.mailpass.MailPass;
import im.mailpass.model.OtpResponse;
import im.mailpass.model.VerifyResponse;

MailPass client = new MailPass("mp_live_your_api_key_here");

// Send OTP
OtpResponse otp = client.otp().send("user@example.com", "login");
System.out.println(otp.getRequestId());

// Verify OTP
VerifyResponse result = client.otp().verify(
    otp.getRequestId(), "123456"
);

if (result.isSuccess()) {
    System.out.println("Verified! " + result.getEmail());
}

Subscribers — List & Create

// List subscribers
SubscriberList subs = client.subscribers().list(1, 1, 20);
for (Subscriber sub : subs.getData()) {
    System.out.println(sub.getEmail() + " " + sub.getStatus());
}

// Create subscriber
Subscriber newSub = client.subscribers().create(
    CreateSubscriberRequest.builder()
        .email("new@example.com")
        .name("Jane Doe")
        .listId(1)
        .tags(List.of("newsletter"))
        .doubleOptin(true)
        .build()
);
System.out.println(newSub.getUuid());

Error Handling

import im.mailpass.exception.*;

try {
    OtpResponse response = client.otp().send("user@example.com");
} catch (ValidationException e) {
    System.err.println("Validation: " + e.getMessage());
    System.err.println("Details: " + e.getDetails());
} catch (RateLimitException e) {
    System.err.println("Rate limited. Retry after " + e.getRetryAfter() + "s");
} catch (ApiException e) {
    System.err.println("API error [" + e.getCode() + "]: " + e.getMessage());
}

For the full API reference, see the API Documentation or the interactive Swagger UI.

クッキーを使用しています

ユーザー体験を向上させるためにクッキーを使用しています。許可するクッキーカテゴリを選択できます。 詳細を知る