npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mailtarget/nodejs-sdk

v1.0.2

Published

The Mailtarget NodeJs SDK enable NodeJs developer to work with Mailtarget API efficiently.

Downloads

1

Readme

Mailtarget NodeJs SDK

The Mailtarget NodeJs SDK enable NodeJs developer to work with Mailtarget API efficiently.

Getting Started

Requirement

Make sure you have LTS version of NodeJs, minimum NodeJs v14

Installation

To install the SDK to your project, you could get the package from NPM via following command.

# NPM
npm install @mailtarget/nodejs-sdk

# Yarn
yarn add @mailtarget/nodejs-sdk

# PNPM
pnpm add @mailtarget/nodejs-sdk

Authentication

You have to create a mailtarget account to get an API Key. To manage your API Key navigate to the page by clicking Configuration on the navbar in the mailtarget dashboard and then select API Key.

Setup Client

Basic Usage

const { Layang } = require('@mailtarget/nodejs-sdk');

const sender = { email: '[email protected]', name: 'John Doe' };
const subject = 'mailtarget Email Test';
const bodyHtml = `
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Layang</title>
    </head>
    <body style="font-family: "Roboto", "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif">
      <h1>Hello World!!!</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
      <br/><br/>
      <p style="color: #8A8A8A">powered by <a target="_blank" href="https://mailtarget.co" style="color: #8A8A8A">mailtarget</a></p>
    </body>
    </html>
`;
const to = [
  { email: '[email protected]', name: 'Jane Doe' },
];

const sendMail = async () => {
  const mailtarget = new Layang('mailtarget-api-key', sender);
  const transmissionId = await mailtarget.sendMessage(subject, to, bodyHtml);
  if (transmissionId) {
    console.log('Email sent, ID = ', transmissionId);
  } else {
    console.error(mailtarget.getErrorMessage());
  }
};

sendMail();

Using Email Template

If you already using mailtarget Template Creator, you could use that template to send an email by invoking sendMessageTempalate function and pass the templateId as a parameter. Here is an example :

const { Layang } = require('@mailtarget/nodejs-sdk');

const sender = { email: '[email protected]', name: 'John Doe' };
const subject = 'mailtarget Email Test';
const templateId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
const to = [
  { email: '[email protected]', name: 'Jane Doe' },
];

const sendMail = async () => {
  const mailtarget = new Layang('mailtarget-api-key', sender);
  const transmissionId = await mailtarget.sendMessageTemplate(subject, to, templateId);
  if (transmissionId) {
    console.log('Email sent, ID = ', transmissionId);
  } else {
    console.error(mailtarget.getErrorMessage());
  }
};

sendMail();

If you are need to substitute a text using a data you provided (of course you need to set the template accordingly in mailtarget), you could declare it as the fourth parameter of sendMessageTemplate :

...
const substituteData = { lastname: 'Doe', birthdat: '1 January 1975' };
await mailtarget.sendMessageTemplate(subject, to, templateId, substituteData);
...

Optional Configuration

Here is a list of configuration you could make on your email (just make sure you declare it before sendMessag or sendMessageTemplate invocation) :

Carbon Copy (CC)

const cc = [
  { email: '[email protected]', name: 'John Doe' }
];
mailtarget.cc = cc;

Blind Carbon Copy (BCC)

const bcc = [
  { email: '[email protected]', name: 'John Doe' }
];
mailtarget.bcc = bcc;

Body Text

mailtarget.bodyText = 'Your text went here';

Headers

const headers = [
  { name: 'x-header', value: 'your header value' }
];
mailtarget.headers = headers;

Attachment

const attachment = [
  { mimeType: 'application/octet-stream', filename: 'your_file.pdf', value: 'some-value' }
];
mailtarget.attachment = attachment;

Metadata

const metadata = [
  { metaKey: 'meta-value' }
];
mailtarget.metadata = metadata;

Click Tracking

Track a click activity of an email you sent, default set to active. If you prefer it to be disabled, use following line :

mailtarget.setClickTracking(false);

Open Tracking

Track an open activity of an email you sent, default set to active. If you prefer it to be disabled, use following line :

mailtarget.setOpenTracking(false);

Transactional

Treat the email as transactional, default set to active. If you prefer it to be disabled (i.e you want to send a newsletter which has unsubscribe link on it), use following line :

mailtarget.setTransactional(false);