Sends Emails
The latest version of sails should load the hooks automatically just by npm installing
npm i https://github.com/bxfsh/sails-hook-email.git --save
In an older version of Sails, that does not support it you can create the directory /api/hooks
and add a file called email.js
, with the following content
npm i https://github.com/bxfsh/sails-hook-email.git --save
You need to install the package regardless
module.exports = require('sails-hook-email');
In your /config/globals.js
add the following
emailSender: {
user: 'smtp user name',
password: 'smtp password'
},
sails.hooks.email.send(
senderEmail,
[receiverEmail1, receiverEmail2],
'Your email title as String',
rawString, // use this if you want to send raw text
null, // html message
function(err) {
if (err) {
console.log(err);
} else {
// All went well
}
});
sails.hooks.email.send(
senderEmail,
[receiverEmail1, receiverEmail2],
'Your email title as String',
null, // use this if you want to send raw text
messageAsHtml, // html message
function(err) {
if (err) {
console.log(err);
} else {
// All went well
}
});
You can also use promises instead of a callback
sails.hooks.email.send(
senderEmail,
[receiverEmail1, receiverEmail2],
'Your email title as String',
null, // use this if you want to send raw text
messageAsHtml)
.then(function() {
// all went well
}, function(err) {
// Handle Error
});