Socket
Socket
Sign inDemoInstall

mailgun

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mailgun

Mailgun API for Node.js


Version published
Weekly downloads
1.9K
increased by28.91%
Maintainers
0
Weekly downloads
 
Created
Source

node-mailgun

A mailgun API for node.js. At the moment, this really only includes sending functionality.

Initialization

Access to the API is done through the Mailgun object. It's instantiated like so:

var mg = new Mailgun('api-key');

Sending Email

Mailgun's API provides two methods for sending email: raw, and text. Both of them are exposed here.

sendText(sender, recipients, subject, text, servername='', options={}, callback(err))

  • sender - Sender of the message; this should be a full email address (e.g. `example@example.com).
  • recipients - An array (['a@example.com', 'b@example.com']) or string (example@example.com) of recipients; these can be email addresses or HTTP URLs.
  • subject - Message subject
  • text - Message body text
  • servername - The name of the Mailgun server. If you only have one server on your Mailgun account, this can be empty. Otherwise, it should be set to the server you want to send from.
  • options - Optional parameters. See Mailgun's API docs for details on these. At the time of writing, the only supported value is headers, which should be a hash of additional MIME headers you want to send.
  • callback - Callback to be fired when the email is done being sent. This should take a single parameter, err, that will be set to true if the email failed to send.

Mailgun Headers

Mailgun understands a couple headers from options. These are defined below.

  • X-Mailgun-Tag - Used to tag sent emails (defined in Mailgun.MAILGUN_TAG)
  • X-Campaign-Id - Used for tracking campaign data (defined in Mailgun.CAMPAIGN_ID)

sendRaw(sender, recipients, rawBody, servername, callback(err))

  • sender - Sender of the message; this should be a full email address (e.g. example@example.com)
  • recipients - An array (['a@example.com', 'b@example.com']) or string (example@example.com) of recipients; these can be email addresses or HTTP URLs.
  • rawBody - MIME message to send
  • servername - The name of the Mailgun server. If you only have one server on your Mailgun account, this can be empty. Otherwise, it should be set to the server you want to send from.
  • callback - Callback to be fired when the email has finished sending. This function should take a single parameter, err, that will be set to true if the email failed to send.

Example

Here's a complete sending example.

var mailgun = require('mailgun');

var mg = new Mailgun('api-key');
mg.sendText('example@example.com', ['rec1@example.com', 'rec2@example.com'],
  'This is the subject',
  'This is the text',
  'noreply@example.com', {},
  function(err) {
    if (err) console.log('Oh noes');
    else     console.log('Success');
});

TODO:

  • routes
  • mailboxes

FAQs

Package last updated on 01 Jun 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc