README
Email module
Configuration
- Create the Files
config/ENVIRONMENT/email/email_service.json
andconfig/ENVIRONMENT/email/email_repository.json
in your project - Set the content of these config-files to
{}
Setup
- In your http-extension-module in your application run
npm install @5minds/email --save
- In your http-extensions
ioc_module.js
- Require the module with
const email = require('@5minds/email/ioc_module');
- Register the module at the IoC-Container with:
email.registerInContainer(container);
Usage
- Let the IoC-Container inject the
EmailService
into the services that need to send emailService
Methods
- sendSMTPMail(smtpSetup, mail)
- sendSMTPMails(smtpSetup, mails)
- sendSendgridMail(sendgridAPIKay, mail)
- sendSendgridMails(sendgridAPIKay, mails)
Parameter-descriptions:
smtpSetup
{
host: 'smtp.gmail.com',
port: 465,
username: 'heiko.mathes@5minds.de',
password: '*******************',
}
SendgridAPIKey
'*******************'
text
, html
and template
are all optional, but at least one of them has to exist
{
senderName: 'Heiko Mathes',
senderAddress: 'heiko.mathes@gmail.com',
to: ['heiko.mathes@gmail.com'],
subject: 'testMail',
text: 'PlainText',
html: '<b>styledtext</b>'
template: template-object
attachments: attachments-object
},
template-object
the template-object can have one ot the following forms
{
path: '/path/to/a/handlebars/file.hbs',
data: {
testText: 'HAI!',
}
}
or
{
source: '<html><body>testText: <b>{{testText}}</b></body></html>',
data: {
testText: 'HAI!',
}
}
or
{
handlebarsTemplate: a_compiled_handlebars_template_object,
data: {
testText: 'HAI!',
}
}
attachments-object
See Nodemailer - Using attachments
Example
this.emailService.sendSMTPMail({
host: 'smtp.gmail.com',
port: 465,
username: 'heiko.mathes@5minds.de',
password: '************************',
}, {
senderName: 'Heiko Mathes',
to: ['heiko.mathes@gmail.com'],
subject: 'testMail',
template: {
path: './testTemplate.hbs',
data: {
testText: 'HAI!',
},
},
});
Config
Service-Config
{
}
Repository-Config
{
"overwriteReceiver": "some@mail.address", // optional, overwrites the direct receiver of all mails
"smtp": { // optional, default smtp-settings
"host": "smtp.gmail.com",
"port": 465,
"username": "heiko.mathes@5minds.de",
"password": "*******************"
},
"sendgrid": { // optional, default sendgrid-settings
"APIKey": "*******************"
}
}