Leverege Platform

Leverege Platform

  • Overview
  • JSDocs
  • REST API
  • Help

›Services

Platform Overview

  • Overview
  • Architecture
  • Core Concepts

Guides

  • Platform Setup
  • Building a Project
  • API UI

Services

  • API Server
  • Message Processor
  • Transponder
  • Reason
  • Scheduler
  • Messenger
  • Emailer
  • Rest Server
  • DB Curator

API

  • API
  • Interface
  • Project
  • System
  • Device
  • Blueprint
  • Collection
  • Child
  • History
  • Scenario
  • Script
  • Template
  • Timer
  • User
  • Users

Server Libraries

  • Log
  • Messages
  • Message Queue
  • Cache
  • Lock
  • Limit
  • Cluster Manager
  • Error
  • Exit

Utilities

  • Promise
  • Data Store
  • Factory
  • Path
  • Reasoner
  • Object Util
  • Array Util
  • String Util
  • Base62 Util
  • Value Cache
  • Validator
  • Lol

UI

  • API Redux
  • UI Builder
  • UI Elements
  • UI Redux
  • UI Mapbox Elements
  • UI Active Theme
  • UI Color Elements
  • UI Linear View Elements

Emailer

Emailer's function is to receive email requests in the form of an EmailMsg, queue them, and then forward them to a service that will send the email. Currently Emailer is configured to use the MailGun api, but Emailer can be configured for other services' apis such as SendGrid.

Emailer listens to the messaging service set up with the Leverege Platform. The default message reading configuration is NSQ, and the topic that emailer listens to is email. The format of the message is an EmailMsg, which can be found in the Messages library, and an example is given below.

A message starts by invoking the route method on an instance of a writer created by Message Queue with the email topic and an instance of an EmailMsg. Message Queue writes the message to the Transponder service, which then routes it to this service (Emailer). Emailer does a validation check to make sure the message received is an instance of an EmailMsg. If there is a templateId provided, Emailer fetches the HTML template, and Handlebars is used to insert values from the context into the template. The Message is then sent to Mailgun for the email to be sent to the client.

Configuration

Required

There are 4 config variable that are required to run this service.

NameDescription
MAIL_GUN_API_KEYMailgun Api Key
MAIL_GUN_DOMAINMailgun domain to send emails from
MODEL_FIREBASE_SERVICE_ACCOUNTservice account key to firebase database
MODEL_FIREBASE_DATABASE_URLurl to firebase database

Optional

There are 11 config variables that have defaults set that will need to be specified in the environment if the default is incorrect.

NameDescriptionDefault
EMAIL_TEMPLATES_DIRfile path to where email templates are storednull
TRANSPORT_CONFIGconfig for readers and writers{ type, host, port }
NSQ_HOST_ADDRhost address for NSQ, not needed if TRANSPORT_CONFIG is specified'127.0.0.1'
NSQ_HOST_PORTport for NSQ, not needed if TRANSPORT_CONFIG is specified4150
CACHE_CONFIGconfiguration for the cache db{ type, connection : { host, port } }
LIMIT_CONFIGconfiguration for the limit dbLimit
MAIL_ATTEMPTSmaximum number of delivery attempts before aborting3
MAIL_ATTEMPT_DELAYdelay enforced between email attempts30000
MAIL_GUN_TEMPLATESstring representing the path to the Mailgun templates'./templates/email/'
MAIL_GUN_DEFAULT_SENDERdefault sender email address'[email protected]'
API_SERVERurl of the Leverege api'https://imagine.leverege.com:8181'

EmailMsg

A more detailed message spec can be found in the Messages library.

NameTypeDescription
tostring or arrayrecipients' email addresses
ccstring or arraycarbon copy email list
bccstring or arrayblind carbon copy email list
subjectstringsubject line
textstringoptional message in plain text format
htmlstringoptional message in html format
templatestringid of the template to use
contextobjectobject to give to the template
attachmentsarrayattachment list
attachments[n].filenamestringname of the attachment that the recipients will see
attachments[n].urlstringsource of a file to send as attachment
attachments[n].contentstringbase64 encoded content. Don't use this if url is specified
attachments[n].encodingstringnormally "base64"
← MessengerRest Server →
  • Configuration
  • EmailMsg
Leverege Platform
Docs
Overview
Connect
FacebookLinkedInTwitter
Facebook Open Source