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

@evokegroup/mailgun

v2.0.2

Published

A lightweight library for sending email via Mailgun.

Downloads

9

Readme

@evokegroup/mailgun

A lightweight library for sending email via Mailgun.

Requires NodeJS 18+

Install

npm install @evokegroup/mailgun

MailgunClient

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | apiKey | string | | The Mailgun API key | | domain | string | | The sending domain | | version | string | v3 | The API version |

constructor()

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | apiKey | string | | The Mailgun API key | | domain | string | | The sending domain | | version | string | v3 | The API version |

import { MailgunClient } from '@evokegroup/mailgun';

const mg = new MailgunClient({ apiKey: '*****', domain: 'my.domain.com' });

Methods

sendAPI()

Sends email via the Mailgun API

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | from | string ¦ IMailAddress ¦ MailAddress | | | | to | (string ¦ IMailAddress ¦ MailAddress)[] | | | | cc | (string ¦ IMailAddress ¦ MailAddress)[] | | | | bcc | (string ¦ IMailAddress ¦ MailAddress)[] | | | | subject | string | | | | html | string | | | | text | string | | | | testmode | boolean | false | Sends the request to the Mailgun API but the message will not be sent. | | args | object | {} | Additional API parameters. |

returns Promise<IWebResponse>

import { MailgunClient } from '@evokegroup/mailgun';

const mg = new MailgunClient({ apiKey: '*****', domain: 'my.domain.com' });

mg.sendAPI({
  to: ['[email protected]'],
  from: { name: 'First Last', address: '[email protected]' },
  subject: 'Hello World!',
  html: '<!DOCTYPE html>\r\n<html><head><title>World</title></head><body><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td><table cellpadding="0" cellspacing="0" border="0" width="450" align="center" bgcolor="#cccccc"><tr><td>HTML - Hello World!</td></tr></table></td></tr></table></body></html>',
  text: 'TEXT - Hello World!'
})
  .then((response) => {
    // do something
  })
  .catch((ex) => {
    // handle error
  });

sendMIME()

Sends mail via the Mailgun API MIME method.

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | message | MimeMessage ¦ IMailgunMimeMessage | | The MIME message | | opts | object | {} | Additional options | | opts.forceMultipartAlternative | boolean | false | Force the MIME message to be created using multipart/alternative | | opts.testmode | boolean | false | Sends the request to the Mailgun API but the message will not be sent. | | opts.args | object | {} | Additional API parameters. |

returns Promise<IWebResponse>

Example using @evokegroup/mime

import { MailgunClient } from '@evokegroup/mailgun';
import { MimeMessage } from "@evokegroup/mime";

const mg = new MailgunClient({ apiKey: '*****', domain: 'my.domain.com' });

const message = new MimeMessage();
message.from = { name: 'First Last', address: '[email protected]' };
message.subject = 'Hello World!';
message.to.add('[email protected]');
message.setHTML('<!DOCTYPE html><html><head><title>World</title></head><body><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td><table cellpadding="0" cellspacing="0" border="0" width="450" align="center" bgcolor="#cccccc"><tr><td>HTML - Hello World!</td></tr></table></td></tr></table></body></html>');
message.setText('TEXT - Hello World!');

mg.sendMIME(message)
  .then((response) => {
    // do something
  })
  .catch((ex) => {
    // handle error
  });

Example using another means on MIME message creation

import { MailgunClient } from '@evokegroup/mailgun';

function createMimeMessage() {
  // Create a MIME message by some means and return it as a string
}

const mg = new MailgunClient({ apiKey: '*****', domain: 'my.domain.com' });

mg.sendMIME({
  to: ['[email protected]'], // mailgun requires the recipient list even if it's already in the MIME message
  message: createMimeMessage()
})
  .then((response) => {
    // do something
  })
  .catch((ex) => {
    // handle error
  });

static parseMessage()

Parses an incomming message.

| Parameter | Type | Default | Description | | --------- | ---- | ------- | ----------- | | message | string | | | | all | boolean | false | Parse all the data |

returns Record<string, string> ¦ IMailgunMessage

IMailgunMessage

| Property | Type | | -------- | ---- | | to | string ¦ IMailAddress | | from | string ¦ IMailAddress | | subject | string | | html | string | | text | string |

IMailgunMimeMessage

| Property | Type | | -------- | ---- | | to | (string ¦ IMailAddress ¦ MailAddress)[] | | message | string |