Untuk mengintegrasikan Mailtarget ke aplikasi, situs web, atau sistem Anda dengan fungsi email menggunakan Java itu mudah.
Endpoints
Semua panggilan ke API perlu dimulai dengan URL dasar yang sesuai:
Mailtarget production |
Implementasi
Berikut adalah kode dasar, salin dan tempel perintah Java di bawah ini ke terminal Anda, Anda dapat menyesuaikan kontennya sesuai kebutuhan Anda
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();
}
Catatan :
API_KEY → ganti dengan API Key
SENDER_EMAIL → ganti dengan sender email
SENDER_NAME → ganti dengan change with sender name
RECIPIENT_EMAIL → ganti dengan recipient email
RECIPIENT_NAME → ganti dengan recipient name
TEMPLATE_ID → ganti dengan template ID