Learn how to use the Mailzeet API to send mails to recipients.
This section guides you through the process of sending an email using the Mailzeet API. The Mailzeet API allows you to send transactional emails reliably and efficiently. To get started, you'll need to provide specific details about the email, including sender information, recipient details, subject, template ID, and customizable parameters.
This guide will walk you through the steps to collect these details, format your request, and understand the response.
Step 1: Collect the Email Details
To send an email, you need to gather the following required information:
Sender: Information about the sender of the email.
Recipients: A list of recipients to whom the email will be sent.
Subject: The subject line of the email.
Template ID: The ID of the email template to use, if applicable. You can find the templates on the Mailzeet dashboard, on the Templates page.
Params: Customizable variables used in the email template.
Fields used for the requests
Below is a detailed table of the fields you need to or can include in your request:
Step 2: Send the Request
Once you have collected the necessary details, you can send an email using the Mailzeet API by making a POST request to the following endpoint: POST https://api.mailzeet.com/v1/mails
Example Request Body
{"sender": {"email":"hello@mailzeet.com","name":"Mailzeet" },"recipients": [ {"email":"john@mailzeet.com","name":"John Doe" } ],"subject":"Hello from {company}!","text":"This is just a friendly hello from your friends at {company}.","html":"<b>This is just a friendly hello from your friends at {company}.</b>","template_id":"xxxxxx","params": {"company":"Mailzeet" }}
Example Response
After sending the request, you will receive a response from the Mailzeet API. The response will confirm whether the email was sent successfully or if there were any errors.
{"message":"Email sent successfully.","data": {"id":"email-id-12345","status":"sent" },"errors":null}
This response includes a message indicating the success of the operation, a data object with the email ID and status, and an errors field which will be null if there are no errors.
By following these steps, you can successfully send emails using the Mailzeet API. If you encounter any issues, refer to the response for error details and adjust your request accordingly.
Here are some examples of the same request in some popular languages.
curl-XPOSThttps://api.mailzeet.com/v1/mails \-H "Content-Type: application/json" \-d '{ "sender": { "email": "hello@mailzeet.com", "name": "Mailzeet" }, "recipients": [ { "email": "john@mailzeet.com", "name": "John Doe" } ], "subject": "Hello from {company}!", "text": "This is just a friendly hello from your friends at {company}.", "html": "<b>This is just a friendly hello from your friends at {company}.</b>", "template_id": "xxxxxx", "params": { "company": "Mailzeet" }}'
constfetch=require('node-fetch');consturl="https://api.mailzeet.com/v1/mails";constpayload= { sender: { email:"hello@mailzeet.com", name:"Mailzeet" }, recipients: [ { email:"john@mailzeet.com", name:"John Doe" } ], subject:"Hello from {company}!", text:"This is just a friendly hello from your friends at {company}.", html:"<b>This is just a friendly hello from your friends at {company}.</b>", template_id:"xxxxxx", params: { company:"Mailzeet" }};constheaders= {"Content-Type":"application/json"};fetch(url, { method:"POST", headers: headers, body:JSON.stringify(payload)}).then(response =>response.json()).then(data =>console.log(data)).catch(error =>console.error('Error:', error));
import requestsurl ="https://api.mailzeet.com/v1/mails"payload ={"sender":{"email":"hello@mailzeet.com","name":"Mailzeet"},"recipients": [{"email":"john@mailzeet.com","name":"John Doe"} ],"subject":"Hello from {company}!","text":"This is just a friendly hello from your friends at {company}.","html":"<b>This is just a friendly hello from your friends at {company}.</b>","template_id":"xxxxxx","params":{"company":"Mailzeet"}}headers ={"Content-Type":"application/json"}response = requests.post(url, json=payload, headers=headers)print(response.json())
packagemainimport ("bytes""encoding/json""fmt""net/http")funcmain() { url :="https://api.mailzeet.com/v1/mails" payload :=map[string]interface{}{"sender": map[string]string{"email": "hello@mailzeet.com","name": "Mailzeet", },"recipients": []map[string]string{ {"email": "john@mailzeet.com","name": "John Doe", }, },"subject": "Hello from {company}!","text": "This is just a friendly hello from your friends at {company}.","html": "<b>This is just a friendly hello from your friends at {company}.</b>","template_id": "xxxxxx","params": map[string]string{"company": "Mailzeet", }, } jsonData, err := json.Marshal(payload)if err !=nil { fmt.Println("Error marshaling JSON:", err)return } req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))if err !=nil { fmt.Println("Error creating request:", err)return } req.Header.Set("Content-Type", "application/json") client :=&http.Client{} resp, err := client.Do(req)if err !=nil { fmt.Println("Error sending request:", err)return }defer resp.Body.Close()var result map[string]interface{} json.NewDecoder(resp.Body).Decode(&result) fmt.Println(result)}
importjava.io.OutputStream;importjava.net.HttpURLConnection;importjava.net.URL;importjava.nio.charset.StandardCharsets;publicclassMailzeetEmailSender {publicstaticvoidmain(String[] args) {try {URL url =newURL("https://api.mailzeet.com/v1/mails");HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setDoOutput(true);conn.setRequestMethod("POST");conn.setRequestProperty("Content-Type","application/json");String payload ="{"+"\"sender\": {\"email\": \"hello@mailzeet.com\", \"name\": \"Mailzeet\"},"+"\"recipients\": [{\"email\": \"john@mailzeet.com\", \"name\": \"John Doe\"}],"+"\"subject\": \"Hello from {company}!\","+"\"text\": \"This is just a friendly hello from your friends at {company}.\","+"\"html\": \"<b>This is just a friendly hello from your friends at {company}.</b>\","+"\"template_id\": \"xxxxxx\","+"\"params\": {\"company\": \"Mailzeet\"}"+"}";byte[] input =payload.getBytes(StandardCharsets.UTF_8);OutputStream os =conn.getOutputStream();os.write(input,0,input.length);int responseCode =conn.getResponseCode();System.out.println("Response Code : "+ responseCode);// Further processing can be added here to read the response } catch (Exception e) {e.printStackTrace(); } }}