Mail service by Paralect
This client service by Paralect. It is using mailgun node client to send emails.
Also it can help you create new emails templates. It is using handlebars for this.
Let's dive into the docs.
Index
- MailService class
- Commands
MailService class
To create a MailService class you should provide several params to its constructor
const MailService = require('@paralect/mail-service-client');
const mailService = new MailService({
mode: 'development',
isSendEmail: false,
savedEmailHtmlPath: __dirname,
mailgun: {
apiKey: 'test',
domain: 'test.info',
},
renderConfigs: {
layoutsDir: 'templates/build',
root: './',
viewsDir: 'templates/build',
defaultLayout: '_email_layout',
},
});
After that you are able to run send method with several params
send(templateName, templateData, data = {})
templateName - the template name which can be built by mail-service-build command
templateData - template data which will be injected to the template
data - additional email data (subject, email logo and etc.)
Commands
Mail service provide several commands for developer.
mail-service-watch
This command is provide two update all changes that you made with your assets.
This will be helpful for developer.
You can start to create you template without any additional
infrastructure and changes in assets automatically regenerate new email template.
// Definition
mail-service-watch -e "emailTemplate" -l "layoutsDir" -r "root" -v "viewsDir" -d "defaultLayout" -t "templateParams"
// Example
mail-service-watch -e ./samples/report-templates/monthly_report/monthly_report.hbs -l ./samples/report-templates/build/ -r ./ -v ./samples/report-templates/build/ -d _email_layout -t ./samples/templateParams.json
Let' describe all params:
- -p or --emailTemplate - path to your email template.
- -t or --templateParams - json file that contains template params which will be injected to email.
- -l or --layoutsDir,-r or --root,-v or --viewsDir,-d or --defaultLayout - this params related to koa-handlebars renderer
mail-service-build
This command is useful for building your assets to email templates.
// Definition
mail-service-build -e "emailTemplates" "emailTemplate" "emailTemplate" "emailTemplate"
// Example
mail-service-build -e ./samples/report-templates/_email_layout/_email_layout.hbs ./samples/report-templates/custom_range_report/custom_range_report.hbs
It has got one param -e or --emailTemplates which can take multiple params.
These params are source pages for building template result.
That's all folks!