Mailtarget Documentation

C

To integrate Mailtarget to your applications, websites, or systems with email functionality using C 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 C 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
#include <stdio.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; // Inisialisasi libcurl curl_global_init(CURL_GLOBAL_DEFAULT); // Inisialisasi objek CURL curl = curl_easy_init(); if(curl) { // Set URL tujuan curl_easy_setopt(curl, CURLOPT_URL, "https://transmission.mailtarget.co/v1/layang/transmissions"); // Set header permintaan struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "accept: application/json"); headers = curl_slist_append(headers, "Content-Type: application/json"); headers = curl_slist_append(headers, "Authorization: Bearer API_KEY"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); // Set data permintaan const char *data = "{\"bodyText\":\"Congratulation, you just sent email with Mailtarget. You are truly awesome!\",\"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>\",\"from\":{\"email\":\"SENDER_EMAIL\",\"name\":\"SENDER_NAME\"},\"subject\":\"Hello from mailtarget\",\"to\":[{\"email\":\"RECIPIENT_EMAIL\",\"name\":\"RECIPIENT_NAME\"}],\"replyTo\":[{\"email\":\"RECIPIENT_EMAIL\",\"name\":\"RECIPIENT_NAME\"}],\"cc\":[{\"email\":\"RECIPIENT_EMAIL\",\"name\":\"RECIPIENT_NAME\"}],\"bcc\":[{\"email\":\"RECIPIENT_EMAIL\",\"name\":\"RECIPIENT_NAME\"}]}"; curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data); // Lakukan permintaan HTTP POST res = curl_easy_perform(curl); if(res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res)); // Cleanup curl_slist_free_all(headers); curl_easy_cleanup(curl); } // Cleanup libcurl curl_global_cleanup(); return 0; }

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