Quick setup examples
Java
Send your first email from Java using the built-in HttpClient against the MailBlastr API.
MailBlastr has no Java SDK — you send email by POSTing JSON to https://api.mailblastr.com/emails. The example below uses the java.net.http.HttpClient introduced in Java 11, so no dependencies are required.
Prerequisites
- A MailBlastr API key.
- A verified domain to send from.
- Java 11 or newer (for the built-in
HttpClient).
1. Set your API key
.env
MAILBLASTR_API_KEY=mb_xxxxxxxxx2. Send emails using HTML
Main.java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("MAILBLASTR_API_KEY");
String body = """
{
"from": "Acme <onboarding@yourdomain.com>",
"to": ["delivered@example.com"],
"subject": "it works!",
"html": "<strong>hello world</strong>"
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.mailblastr.com/emails"))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}
}In Spring Boot, you can use
RestClient or WebClient against the same URL with the same Bearer header. See Send an email for all fields.