Mailtarget Documentation

Java

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:

Mailtarget productionhttps://transmission.mailtarget.co/v1

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.

VariableDescriptions
API_KEYAPI Key in dashboard
CURLOPT_URLhttps://transmission.mailtarget.co/v1/layang/transmissions
OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/json"); String content = "{" + " //populate email body" + " \"bodyText\": \"Example Email with Link\\Dear [Name],\\We 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.\\Please click the following link to confirm your acceptance of the offer:\\Accept Offer (https://example.com/accept_offer)\\If you have any questions or concerns, please do not hesitate to contact us at info@example.com.\\Best regards,\\[Your Name]\[Company Name]\"," + " \"from\": {" + " \"email\": \"default@sandbox.mailtarget.co\"," + " \"name\": \"Sandbox Dev\"" + " }," + " \"subject\": \"Example email with bodytext\"," + "" + " //populate email recipient" + " \"to\": [" + " {" + " \"email\": \"email@email.com\"," + " \"name\": \"string\"" + " }" + " ]," + " \"replyTo\": [" + " {" + " \"email\": \"email@email.com\"," + " \"name\": \"string\"" + " }" + " ]," + " \"cc\": [" + " {" + " \"email\": \"email@email.com\"," + " \"name\": \"string\"" + " }" + " ]," + " \"bcc\": [" + " {" + " \"email\": \"email@email.com\"," + " \"name\": \"string\"" + " }" + " ]," + " \"headers\": [" + " {" + " \"name\": \"\"," + " \"value\": \"\"" + " }" + " ]," + " \"attachments\": [" + " {" + " \"mimeType\": \"image/png\"," + " \"filename\": \"FILE_NAME.png\"," + " \"value\": \"BASE64_ENCODED_CONTENT\"" + " }" + " ]," + " \"metadata\": {" + " \"key1\": \"value1\"," + " \"key2\": \"value2\"" + " }" + "}"; 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