Coder Social home page Coder Social logo

postal-node's Introduction

Postal for Node

This library helps you send e-mails through the open source mail delivery platform, Postal in Node.

Installation

Install the library using NPM:

$ npm install @atech/postal --save

Usage

Sending an email is very simple. Just follow the example below. Before you can begin, you'll need to login to your installation's web interface and generate new API credentials.

// Include the Postal library
var Postal = require('@atech/postal');

// Create a new Postal client using a server key generated using your
// installation's web interface
var client = new Postal.Client('https://postal.yourdomain.com', 'your-api-key');

// Create a new message
var message = new Postal.SendMessage(client);

// Add some recipients
message.to('[email protected]');
message.to('[email protected]');
message.cc('[email protected]');
message.bcc('[email protected]');

// Specify who the message should be from - this must be from a verified domain
// on your mail server
message.from('[email protected]');

// Set the subject
message.subject('Hi there!');

// Set the content for the e-mail
message.plainBody('Hello world!');
message.htmlBody('<p>Hello world!</p>');

// Add any custom headers
message.header('X-PHP-Test', 'value');

// Attach any files
message.attach('textmessage.txt', 'text/plain', 'Hello world!');

// Send the message and get the result
message.send()
  .then(function (result) {
    var recipients = result.recipients();
    // Loop through each of the recipients to get the message ID
    for (var email in recipients) {
      var message = recipients[email];
      console.log(message.id());    // Logs the message ID
      console.log(message.token()); // Logs the message's token
    }
  }).catch(function (error) {
    // Do something with the error
    console.log(error.code);
    console.log(error.message);
  });

postal-node's People

Contributors

adamcooke avatar robertlyall avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.