Skip to main content
Java
S
Written by Support Mailtarget
Updated over a week ago

To integrate Mailtarget to your applications, websites, or systems with email functionality using Java is easy.

Endpoints

All calls to the API need to start with the appropriate base URL:

Implementation

Here’s the basic code, copy and paste the Java command below into your terminal, you can customize the content according to your needs.

Variable

Descriptions

API_KEY

API Key in dashboard

CURLOPT_URL

OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
String content = "{\n" +
" //populate email body\n" +
" \"bodyText\": \"Example Email with Link\\n\\nDear [Name],\\n\\nWe are pleased to inform you that you have been selected for the [Position] role at [Company Name]. Your skills and experience make you an excellent fit for the position, and we look forward to having you join our team.\\n\\nPlease click the following link to confirm your acceptance of the offer:\\n\\nAccept Offer (https://example.com/accept_offer)\\n\\nIf you have any questions or concerns, please do not hesitate to contact us at [email protected].\\n\\nBest regards,\\n\\n[Your Name]\\n[Company Name]\",\n" +
" \"from\": {\n" +
" \"email\": \"[email protected]\",\n" +
" \"name\": \"Sandbox Dev\"\n" +
" },\n" +
" \"subject\": \"Example email with bodytext\",\n" +
"\n" +
" //populate email recipient\n" +
" \"to\": [\n" +
" {\n" +
" \"email\": \"[email protected]\",\n" +
" \"name\": \"string\"\n" +
" }\n" +
" ],\n" +
" \"replyTo\": [\n" +
" {\n" +
" \"email\": \"[email protected]\",\n" +
" \"name\": \"string\"\n" +
" }\n" +
" ],\n" +
" \"cc\": [\n" +
" {\n" +
" \"email\": \"[email protected]\",\n" +
" \"name\": \"string\"\n" +
" }\n" +
" ],\n" +
" \"bcc\": [\n" +
" {\n" +
" \"email\": \"[email protected]\",\n" +
" \"name\": \"string\"\n" +
" }\n" +
" ],\n" +
" \"headers\": [\n" +
" {\n" +
" \"name\": \"\",\n" +
" \"value\": \"\"\n" +
" }\n" +
" ],\n" +
" \"attachments\": [\n" +
" {\n" +
" \"mimeType\": \"image/png\",\n" +
" \"filename\": \"FILE_NAME.png\",\n" +
" \"value\": \"BASE64_ENCODED_CONTENT\"\n" +
" }\n" +
" ],\n" +
" \"metadata\": {\n" +
" \"key1\": \"value1\",\n" +
" \"key2\": \"value2\"\n" +
" }\n" +
"}";

RequestBody body = RequestBody.create(mediaType, content);
Request request = new Request.Builder()
.url("https://transmission.mailtarget.co/v1/layang/transmissions")
.method("POST", body)
.addHeader("accept", "application/json")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer API_KEY")
.build();
Response response = client.newCall(request).execute();
}

Note :

  • API_KEY → change with API Key

  • SENDER_EMAIL → change with sender email

  • SENDER_NAME → change with sender name

  • RECIPIENT_EMAIL → change with recipient email

  • RECIPIENT_NAME → change with recipient name

Did this answer your question?