api-mailer

0.1.3 • Public • Published

NPM version Downloads

Description

Mailer normalizes different service providers APIs (AWS SES, SendGrid, etc) into a single, consistent API interface. This provides modularity and portability. For example, if you change service providers (from SES to SendGrid), the API calls would remain the same. The only thing that would change would be the config file.

Install

$ npm install api-mailer

Setup

AWS: Setup your config file with your AWS SES credentials. See example.

SendGrid: Setup your config file with your SendGrid API Key. See example.

Basic usage

var sgConfig = require('./config/sendgrid-example.json')
var awsConfig = require('./config/aws-example.json')
 
var EmailMessage = require('dc-email-message');
var Mailer = require('api-mailer');
var Person = require('dc-person');
//It will detect the service provider on config file and use it
var mailer = new Mailer(sgConfig);
 
const recipient = new Person();
recipient.givenName = "RecipientFirst";
recipient.familyName = "RecipientLast";
recipient.email = "test@recipient.com";
 
const sender = new Person();
sender.givenName ="SenderFirst";
sender.familyName = "SenderLastName";
sender.email = "hello@sender.com";
 
let email = new EmailMessage();
email.recipient = recipient;
email.sender = sender;
email.subject = "Subject line";
email.text = "This is the text content"
 
mailer.sendEmail(email)
    .then(response => {/* success */})
    .catch(error => {/* error */})
 
 

Operations

Operation Params
sendEmail {email}

Tests

$ npm test

/api-mailer/

    Package Sidebar

    Install

    npm i api-mailer

    Weekly Downloads

    2

    Version

    0.1.3

    License

    UNLICENSED

    Unpacked Size

    7.3 kB

    Total Files

    10

    Last publish

    Collaborators

    • eaortiz2016
    • josebarrios