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.
var Postal = require('@atech/postal');
var client = new Postal.Client('https://postal.yourdomain.com', 'your-api-key');
var message = new Postal.SendMessage(client);
message.to('john@example.com');
message.to('mary@example.com');
message.cc('mike@example.com');
message.bcc('secret@awesomeapp.com');
message.from('test@test.postal.io');
message.subject('Hi there!');
message.plainBody('Hello world!');
message.htmlBody('<p>Hello world!</p>');
message.header('X-PHP-Test', 'value');
message.attach('textmessage.txt', 'text/plain', 'Hello world!');
message.send()
.then(function (result) {
var recipients = result.recipients();
for (var email in recipients) {
var message = recipients[email];
console.log(message.id());
console.log(message.token());
}
}).catch(function (error) {
console.log(error.code);
console.log(error.message);
});