Untuk mengintegrasikan Mailtarget ke aplikasi, situs web, atau sistem Anda dengan fungsi email menggunakan Go 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 Go di bawah ini ke terminal Anda, Anda dapat menyesuaikan kontennya sesuai kebutuhan Anda
Variable | Descriptions |
API_KEY | API Key in dashboard |
CURLOPT_URL |
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://transmission.mailtarget.co/v1/layang/transmissions"
method := "POST"
payload := strings.NewReader(`{
"bodyText": "Body Text",
"bodyHtml": "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><title>Body HTML</title></head><body><p>Body HTML</p></body></html>",
"from": {
"email": "SENDER_EMAIL",
"name": "SENDER_NAME"
},
"subject": "Example email",
"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"
}
],
"headers":[
{
"name":"",
"value":""
}
],
"attachments":[
{
"mimeType": "image/png",
"filename": "FILE_NAME.png",
"value": "BASE64_ENCODED_CONTENT"
}
],
"metadata":{
"key1":"value1",
"key2":"value2"
},
"templateId":"TEMPLATE_ID"
}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer API_KEY")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
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