Send mail via Node

### 🛠️ Installation

To install the ZeptoMail, you first need to [Sign Up](https://www.zoho.com/zeptomail/) to ZOHO.

Then you need to install [Node.js](http://nodejs.org/) and [npm](https://npmjs.org/).

Installing `zeptomail` is simple and easy. Start by entering the following command in your system terminal:

```markup
npm install zeptomail
```

## 📊 Obtain an API Key

Grab your API Key from the [Zeptomail](https://www.zoho.com/zeptomail/help/smtp-api.html#alink2)

## 📒 Example

Example for email sending (sendMail), sending single email using tempalte (sendMailWithTemplate) and sending batch emails using template (mailBatchWithTemplate) are available below.

### Send mail

```js
// For ES6, set type: "module" in package.json.
import { SendMailClient } from "zeptomail";

// For CommonJS
var { SendMailClient } = require("zeptomail");

const url = "api.zeptomail.com/";
const token = "<Send mail token>";

let client = new SendMailClient({url, token});

client.sendMail({
    "from": 
    {
        "address": "test@example.com",
        "name": "test"
    },
    "to": 
    [
        {
        "email_address": 
            {
                "address": "test1@example.com",
                "name": "test1"
            }
        }
    ],
    "reply_to": 
    [
        {
            "address": "test2@example.com",
            "name": "test2"
        } 
    ],
    "subject": "Sending with ZeptoMail to have good experience",
    "textbody": "Easy to do from anywhere, with  Node.js",
    "htmlbody": "<strong>Easy to do from anywhere, with  Node.js</strong>",
    "cc": 
    [
        {
        "email_address": 
            {
                "address": "test3@example.com",
                "name": "test3"
            }
        }
    ],
    "bcc": 
    [
        {
        "email_address": 
            {
                "address": "test4@example.com",
                "name": "test4"
            }
        }
    ],
    "track_clicks": true,
    "track_opens": true,
    "client_reference": "<client reference>",
    "mime_headers": 
        {
            "X-Zylker-User": "test-xxxx"
        },
    "attachments": 
    [
        {
            "content": "..x+SEXa3zKfnDnBA2qExtXikBpUAFABQAhGSPY/0IoAWgD/2Q==",
            "mime_type": "image/jpg",
            "name": "DM-welcome-guide"
        },
        {
            "file_cache_key": "<File Cache Key>",
            "name": "DM-reports"
        }
    ],
    "inline_images": 
    [
        {
            "mime_type": "image/jpg",
            "content": "...x+SEXa3zKfnDnBA2qExtXikBpUAFABQAhGSPY/0IoAWgD/2Q==",
            "cid": "img-welcome-design"
        },
        {
            "file_cache_key": "<File Cache Key>",
            "cid": "img-CTA"
        }
    ]
}).then((resp) => console.log("success")).catch((error) => console.log("error"));
```

### Send batch mail 

```js
// For ES6, set type: "module" in package.json.
import { SendMailClient } from "zeptomail";

// For CommonJS
var { SendMailClient } = require("zeptomail");

const url = "api.zeptomail.com/";
const token = "<Send mail token>";

client.sendBatchMail({
    "from": {
        "address": "test@example.com",
        "name": "test"
    },
    "to": [
        {
            "email_address": {
                "address": "test1@example.com",
                "name": "test1"
            },
            "merge_info": {
                "name": "Micheal scott"
            }
        }
    ],
    "reply_to": 
    [
        {
            "address": "test2@example.com",
            "name": "test2"
        } 
    ],
    "subject": "Sending with ZeptoMail to have good experience",
    "textbody": "Hi {{name}}, sending email is easy to do from anywhere, with  Node.js",
    "htmlbody": "Hi {{name}},<br /><strong> Sending email is easy to do from anywhere, with  Node.js</strong>",
    "cc": 
    [
        {
        "email_address": 
            {
                "address": "test3@example.com",
                "name": "test3"
            }
        }
    ],
    "bcc": 
    [
        {
        "email_address": 
            {
                "address": "test4@example.com",
                "name": "test4"
            }
        }
    ],
    "track_clicks": true,
    "track_opens": true,
    "client_reference": "<client reference>",
    "mime_headers": 
        {
            "X-Zylker-User": "test-xxxx"
        },
    "attachments": 
    [
        {
            "content": "..x+SEXa3zKfnDnBA2qExtXikBpUAFABQAhGSPY/0IoAWgD/2Q==",
            "mime_type": "image/jpg",
            "name": "DM-welcome-guide"
        },
        {
            "file_cache_key": "<File Cache Key>",
            "name": "DM-reports"
        }
    ],
    "inline_images": 
    [
        {
            "mime_type": "image/jpg",
            "content": "...x+SEXa3zKfnDnBA2qExtXikBpUAFABQAhGSPY/0IoAWgD/2Q==",
            "cid": "img-welcome-design"
        },
        {
            "file_cache_key": "<File Cache Key>",
            "cid": "img-CTA"
        }
    ]
}).then((resp) => console.log("success")).catch((error) => console.log("error"));
```

### Send template mail 
```js
// For ES6, set type: "module" in package.json.
import { SendMailClient } from "zeptomail";

// For CommonJS
var { SendMailClient } = require("zeptomail");

const url = "api.zeptomail.com/";
const token = "<Send mail token>";

client.sendMailWithTemplate({
    "template_key": "<template key>",
    "template_alias": "<template's alias>",
    "from": {
        "address": "test@example.com",
        "name": "test"
    },
    "to": [
        {
            "email_address": {
                "address": "test1@example.com",
                "name": "test1"
            }
        }
    ],
    "cc": [
        {
            "email_address": {
                "address": "test3@example.com",
                "name": "test3"
            }
        }
    ],
    "bcc": [
        {
            "email_address": {
                "address": "test5@example.com",
                "name": "test5"
            }
        }
    ],
    "merge_info": {
        "contact_number": "8787xxxxxx789",
        "company": "example.com"
    },
    "reply_to": [
        {
            "address": "test7@example.com",
            "name": "test7"
        }
    ],
    "client_reference": "<client reference>",
    "mime_headers": {
        "X-Test": "test"
    }
}).then((resp) => console.log("success")).catch((error) => console.log("error"));
```

### Send batch template mail 

```js
// For ES6, set type: "module" in package.json.
import { SendMailClient } from "zeptomail";

// For CommonJS
var { SendMailClient } = require("zeptomail");

const url = "api.zeptomail.com/";
const token = "<Send mail token>";

client.mailBatchWithTemplate({
    "template_key": "<template's key>",
    "template_alias": "<template's alias>",
    "from": {
        "address": "test@example.com",
        "name": "test"
    },
    "to": [
        {
            "email_address": {
                "address": "test1@example.com",
                "name": "test1"
            },
            "merge_info": {
                "contact_number": "8787xxxxxx789",
                "company": "example.com"
            }
        }
    ],
    "reply_to": [
        {
            "address": "test@example.com",
            "name": "test"
        }
    ],
    "client_reference": "<client reference>",
    "mime_headers": {
        "X-Test": "test"
    }
}).then((resp) => console.log("success")).catch((error) => console.log("error"));
```

## 📒 Contact Us

Contact us at `support@zeptomail.com` for any questions regarding Zoho ZeptoMail.