zeptomail

5.0.0 • Public • Published

Send mail via Node

Installation

To install the ZeptoMail, you first need to Sign Up to ZOHO.

Then you need to install Node.js and npm.

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

npm install zeptomail

Obtain an API Key

Grab your API Key from the Zeptomail

Example

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

// 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 anywhere, even with Node.js",
    "htmlbody": "<strong>Easy to do anywhere, even 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"));

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"));


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"));

Keywords

none

Install

npm i zeptomail

DownloadsWeekly Downloads

1,066

Version

5.0.0

License

MIT

Unpacked Size

31.6 kB

Total Files

6

Last publish

Collaborators

  • zeptomail_npm