1.1.0 • Published 4 years ago

iffr-ticket-mailer v1.1.0

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

IFFR Ticket Mailer

A small node.js library for sending an email with an e-ticket attachment via Mailgun.

Installation

Installing using npm:

npm i iffr-ticket-mailer

Usage

const ticketMailer = new TicketMailer('my-mailgun-api-key', 'my-domain.com', 'path/to/render/directory/');
ticketMailer.send('path/to/e-ticket/template', 'path/to/email/template', 'email subject', 'SenderName <sender@my-domain.com>', 'recipient@email.com', 'myQrCode', {});

Templates

The Handlebars template engine is used for rendering the attachment and email template. The data property that is passed to the send function will be available in the templates.

For display purposes the rendered QR code will be added to the template data on the property ___QRCode. This contains a Data URI representation of the QR Code image. In the attachment template this can be used like <img src="{{___QRCode}}" width="150" height="150">.

API

constructor(apiKey, domain, renderDir)

PropertyTypeDescription
apiKeystringMailgun api key.
domainstringMailgun domain.
renderDirstringPath to the directory where attachment pdf's will be rendered to.

.send(subject, from, to, emailTemplatePath, emailTemplateData, attachments)

Send e-ticket by email.

PropertyTypeDescription
subjectstringSubject line of the email.
fromstringSender email address.
tostringRecipient email address.
emailTemplatePathstringPath to the email handlebars template.
emailTemplateDatastringTemplate data that will be passed to the email template on render.
attachmentsstringCollection of attachments that will be send with the email. See description below.

Attachments

PropertyTypeDescription
templateFilePathstringPath to the attachment handlebars template.
tokenstringQR code that will be rendered on the ticket.
dataobjectTemplate data that will be passed to the email and attachment template on render.