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

To integrate Mailtarget to your applications, websites, or systems with email functionality using Kotlin 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 Kotlin command below into your terminal, you can customize the content according to your needs.

Variable

Descriptions

API_KEY

API Key in dashboard

CURLOPT_URL

val client = OkHttpClient()
val mediaType = "application/json".toMediaType()
val body = "{\n \"bodyText\": \"Congratulation, you just sent email with Mailtarget. You are truly awesome!\",\n \"bodyHtml\": \"<!DOCTYPE html><html lang=\\\"en\\\"><head><meta charset=\\\"UTF-8\\\"><title>Hello from Mailtarget</title></head><body><p>Congratulation, you just sent email with Mailtarget. You are truly awesome!</p></body></html>\",\n \"from\": {\n \"email\": \"SENDER_EMAIL\",\n \"name\": \"SENDER_NAME\"\n },\n \"subject\": \"Hello from Mailtarget\",\n \"to\": [\n {\n \"email\": \"RECIPIENT_EMAIL\",\n \"name\": \"RECIPIENT_NAME\"\n }\n ]\n,\n \"cc\": [\n {\n \"email\": \"RECIPIENT_EMAIL\",\n \"name\": \"RECIPIENT_NAME\"\n }\n ]\n,\n \"bcc\": [\n {\n \"email\": \"RECIPIENT_EMAIL\",\n \"name\": \"RECIPIENT_NAME\"\n }\n ]\n}".toRequestBody(mediaType)
val request = Request.Builder()
.url("https://transmission.mailtarget.co/v1/layang/transmissions")
.post(body)
.addHeader("accept", "application/json")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer API_KEY")
.build()
val response = client.newCall(request).execute()
  • 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?