1.0.2 • Published 6 years ago

nodelastic v1.0.2

Weekly downloads
25
License
ISC
Repository
github
Last release
6 years ago

This is a NodeJS library to allow you to quickly and easily use the Elastic Email Web API V2.

Installation

$ npm install nodelastic

Prerequisites

Functions

/**
 * Set default configuration that can be used to set common params.
 * @param {Object}         options     Object can be constructed from send parameters
 * Example : 
 *   var options { from : "from@domain.com", fromName : "Sender" }
 *   client.setConfig( options )
 */
function setConfig( options ) { ... }

/**
 * Returns a Promise of http response from Elastic Email
 * @param {Object}         params      Parameters that will override default configuration set in setConfig
 * @param {Array.<Object>} attachments Optional parameter. Please refer to the table below for more details.
 */
function send( params, attachments ) { ... }

params object passed into send function or options object passed into setConfig should have the following format

KeyData TypeRequiredDescription
subjectStringtrueEmail subject
msgToStringtrueList of email recipients (visible to all other recipients of the message as TO MIME header)
fromStringtrueFrom email address
fromNameStringtrueDisplay name for from email address
bodyHtmlStringtrueHtml email body
bodyTextStringtrueText email body
replyToStringfalseEmail address to reply to
replyToNameStringfalseDisplay name of the reply to address
msgCCStringfalseList of email recipients (visible to all other recipients of the message as CC MIME header)
msgBccStringfalseList of email recipients (each email is treated seperately)
channelStringfalseAn ID field (max 191 chars) that can be used for reporting will default to HTTP API or SMTP API
charsetStringfalseText value of charset encoding for example: iso-8859-1, windows-1251, utf-8, us-ascii, windows-1250 and more…
charsetBodyHtmlStringfalseSets charset for body html MIME part (overrides default value from charset parameter)
charsetBodyTextStringfalseSets charset for body text MIME part (overrides default value from charset parameter)
templateStringfalseThe ID of an email template you have created in your account
merge{String,String}falseRequest parameters prefixed by merge like merge_firstname, merge_lastname. If sending to a template you can send merge fields to merge data with the template. Template fields are entered with {firstname}, {lastname} etc. Example: merge_firstname=John
timeOffSetMinutesStringfalseNumber of minutes in the future this email should be sent up to a maximum of 1 year (524160 minutes)
poolNameStringfalseName of your custom IP Pool to be used in the sending process
headers{String,String}falseOptional Custom Headers. Request parameters prefixed by headers_ like headers_customheader1, headers_customheader2. Note: a space is required after the colon before the custom header value. headers_xmailer=xmailer: header-value1
isTransactionalBooleanfalseTrue, if email is transactional (non-bulk, non-marketing, non-commercial). Otherwise, false

attachment object passed into the attachments array should have the following format

KeyData TypeTypeDefault Value
dataString or Bufferrequired
filenameStringrequired
contentTypeStringoptionaltext/plain

Example

var ElasticMail = require('nodelastic');
var client = new ElasticMail('your_api_key_here');
var attachments = [ 
  // CSV
  { data: 'id,name\n1,name_1',
    filename: 'attachment1.csv' },
  // PDF
  { data: fs.readFileSync('filepath_here'),
    filename: 'attachment2.pdf',
    contentType: 'application/pdf' } 
];

client.send({
  from : 'from@domain.com',
  fromName : 'Sender',
  subject : 'Subject',
  msgTo: [ 'to@domain.com' ],
  msgCC: [ 'cc_1@domain.com', 'cc_2@domain.com' ],
  bodyHtml: '<h1>Hello World</h1>',
  textHtml: 'Hello World'
}, attachments).then(console.log);

// will print 
// {"success":true,"data":{"transactionid":"190d1b03-8b01-41a1-8003-17181c1719b0","messageid":"ilXf1Nm38mxuxemecfdbvw2"}}

// You can also set default options, for example having the same from and the name of the sender
// the function below is the same as the client.send above
client.setConfig({
  from : 'from@domain.com',
  fromName : 'Sender'
});
client.send({
  subject : 'Subject',
  msgTo: [ 'to@domain.com' ],
  msgCC: [ 'cc_1@domain.com', 'cc_2@domain.com' ],
  bodyHtml: '<h1>Hello World</h1>',
  textHtml: 'Hello World'
}, attachments).then(console.log);

logo

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago