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:
Field Name
Type
Required
Description
sender
object
no
Details about the sender. Not required if template_id is present and template has default sender set.
sender.email
string
no
Must be an authorized email address for your SMTP server provided on Mailzeet.
sender.name
string
no
Name of the sender.
recipients
object[]
yes
A list of recipient details. Minimum 1, maximum 50.
recipients.email
string
yes
Email address of the recipient.
recipients.name
string
no
Name of the recipient. May not contain ; or ,.
cc
object[]
no
List of CC recipients. Maximum 10.
cc.email
string
yes
Email address of the CC recipient.
cc.name
string
no
Name of the CC recipient. May not contain ; or ,.
bcc
object[]
no
List of BCC recipients. Maximum 10.
bcc.email
string
yes
Email address of the BCC recipient.
bcc.name
string
no
Name of the BCC recipient.
reply_to.email
string
no
Reply-to email address.
reply_to.name
string
no
Name for the reply-to email address.
subject
string
yes *
Subject of the email. Max 255 characters. Not required if template_id is present and template has default subject set.
text
string
yes *
Email represented in a text (text/plain) format. Max size of 1 MB. * Only required if there's no html or template_id present.
html
string
yes *
Email represented in HTML (text/html) format. Max size of 2 MB. * Only required if there's no text or template_id present.
template_id
string
yes *
Template ID to use for the email. * Only required if there's no text or html present.
params
object
no
Allows using personalization in {{var}} syntax. Can be used in the subject, html, text fields, and templates.
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(); } }}