To integrate Mailtarget to your applications, websites, or systems with email functionality using Go is easy.
Endpoints
All calls to the API need to start with the appropriate base URL:
| Mailtarget production | https://transmission.mailtarget.co/v1 |
|---|
Implementation
Here's the basic code, copy and paste the Go command below into your terminal, you can customize the content according to your needs.
| Variable | Descriptions |
|---|---|
| API_KEY | API Key in dashboard |
| CURLOPT_URL | https://transmission.mailtarget.co/v1/layang/transmissions |
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)) }
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
- TEMPLATE_ID → change with template ID