ocemailsender
v1.0.10
Published
OC Email Sender is a library to send email from a html template and using a data object to replace the placeholders in the template. ## Instalation ```bash npm install ocemailsender ``` ## Usage ```javascript const EmailSender = require('ocemailsender');
Downloads
4
Readme
ocemailsender
OC Email Sender is a library to send email from a html template and using a data object to replace the placeholders in the template.
Instalation
npm install ocemailsender
Usage
const EmailSender = require('ocemailsender');
const emailSender = new EmailSender({
smtpHost: 'smtp.gmail.com',
smtpPort: 465,
smtpUser: 'user',
smtpPass: 'password'
})
const data = {
name: 'John',
lastname: 'Doe'
}
emailSender.sendEmail({
from: '[email protected]',
to: '[email protected]',
subject: 'Test email',
templateUrl: 'https://test.com/test.html',
templateHtml: '<h1>Hello <span class="name"></span> <span class="lastname"></span></h1>', // Optional if templateUrl is not provided
data: data,
attachments: [
{
filename: 'test.txt',
content: 'Hello world!'
}
]
})
Caveats
- The template must be a html file.
- TemplateUrl can be http:// or https:// or file://
- If templateHtml is declared, the templateUrl will be ignored.
- The template may have the placeholders in the format
<span class="firstName">
- Also can use handlebars format
{{firstName}}
- If subject is not specified and template have a
<title>
then the title will be used as subject. - To attach files check the nodemailer documentation