UNPKG

pepipost

Version:

Official nodejs library for sending email using web API v5

61 lines (44 loc) 1.97 kB
'use strict'; const lib = require('./lib'); const configuration = lib.Configuration; const controller = lib.MailSendController; configuration.apiKey = '96c909c62bcc1dffacef747979ea8477'; let body = new lib.Send(); body.from = new lib.From(); body.from.email = 'hello@snipperbytes.in'; body.from.name = 'Pepipost'; body.subject = 'Pepipost Test Mail from SDK'; body.content = []; body.content[0] = new lib.Content(); body.content[0].type = lib.TypeEnum.HTML; body.content[0].value = '<html><body>Hello, Welcome to Pepipost Family.<br>My name is [% name %].<br>my love is sending [% love %]</body> <br></html>'; body.personalizations = []; body.personalizations[0] = new lib.Personalizations(); body.personalizations[0].attributes = JSON.parse('{"name":"Pepi","love":"Email"}'); body.personalizations[0].to = []; body.personalizations[0].to[0] = new lib.EmailStruct(); body.personalizations[0].to[0].name = 'Vikram'; body.personalizations[0].to[0].email = 'snipperbytes@gmail.com'; body.personalizations[0].cc = []; body.personalizations[0].cc[0] = new lib.EmailStruct(); body.personalizations[0].cc[0].name = 'to-cc-name'; body.personalizations[0].cc[0].email = 'vikramsahu36@gmail.com'; body.personalizations[0].bcc = []; body.personalizations[0].bcc[0] = new lib.EmailStruct(); body.personalizations[0].bcc[0].name = 'to-bcc-name'; body.personalizations[0].bcc[0].email = 'vikram@pepipost.com'; body.settings = new lib.Settings(); body.settings.footer = true; body.settings.clickTrack = true; body.settings.openTrack = true; body.settings.unsubscribeTrack = true; const promise = controller.createGeneratethemailsendrequest(body); promise.then((response) => { // this block will be executed on successful endpoint call console.log(response); // `response` will be of type 'object' }, (err) => { // this block will be executed on endpoint call failure console.log(err); // `err` is an 'object' containing more information about the error });