epochtalk-emailer
v0.0.2
Published
EpochTalk server for sending emails.
Downloads
4
Readme
#Emailer
Email server for EpochTalk Frontend.
Installation and Configuration
- Checkout repository using git:
$ git clone [email protected]:epochtalk/emailer.git
- Change directories and install dependencies using npm
$ cd emailer
$ npm install
- Add and set the following configs to a
.env
file.
SMTP_HOST=smtp.example.com
[email protected]
SMTP_PASS=password
- Run the server using foreman
$ foreman start -f Profile
##Adding Templates
- Create an html template using doT notation for parameters
- Place html file in
/templates
folder - Add export for new template to
emails.js
###Example
Add Template File (templates/recover-account.html
)
<h3>Account Recovery</h3>
Recover your account by visiting the link below and resetting your password:<br /><br />
<strong>Username</strong>: {{=it.username}}<br />
<strong>Password</strong>:
<a href="{{=it.resetUrl}}">Reset</a>
Add Template Export to email.js
exports.recoverAccount = {
schema: {
username: joi.string().min(1).max(255).required(),
reset_url: joi.string().required(),
email: joi.string().email().required()
},
compile: function(params) {
var template = doT.template(templateFile('recover-account.html'));
return {
from: config.senderEmail,
to: params.email,
subject: '[EpochTalk] Account Recovery',
html: template({ username: params.username, resetUrl: params.reset_url })
};
}
};
schema
- validation schema for email template paramscompile
- returns email object with compiled template
Call Server
Call the emailer server using a library that supports unix domain sockets like request.
var request = require('request');
var params = {
username: 'john',
email: '[email protected]',
reset_url: 'http://localhost:8080/reset/john/123412412412412',
};
request.post({ url:'http://unix:/tmp/epochEmailer.sock:/recoverAccount', formData: params }, function(err, res, body) {
if (body.statusCode === 200) {
console.log(body.message); // success
}
});