2024-03-22 00:14:09 +01:00
|
|
|
const nodemailer = require('nodemailer');
|
|
|
|
|
2024-04-09 15:12:46 +02:00
|
|
|
/**
|
|
|
|
* smtp hook
|
|
|
|
*
|
|
|
|
* @description :: A hook definition. Extends Sails by adding shadow routes, implicit actions,
|
|
|
|
* and/or initialization logic.
|
|
|
|
* @docs :: https://sailsjs.com/docs/concepts/extending-sails/hooks
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = function defineSmtpHook(sails) {
|
2024-03-22 00:14:09 +01:00
|
|
|
let transporter = null;
|
|
|
|
|
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Runs when this Sails app loads/lifts.
|
|
|
|
*/
|
|
|
|
|
|
|
|
async initialize() {
|
2024-04-09 15:12:46 +02:00
|
|
|
if (!sails.config.custom.smtpHost) {
|
|
|
|
return;
|
2024-03-22 00:14:09 +01:00
|
|
|
}
|
2024-04-09 15:12:46 +02:00
|
|
|
|
|
|
|
sails.log.info('Initializing custom hook (`smtp`)');
|
|
|
|
|
|
|
|
transporter = nodemailer.createTransport({
|
|
|
|
pool: true,
|
|
|
|
host: sails.config.custom.smtpHost,
|
|
|
|
port: sails.config.custom.smtpPort,
|
|
|
|
secure: sails.config.custom.smtpSecure,
|
|
|
|
auth: sails.config.custom.smtpUser && {
|
|
|
|
user: sails.config.custom.smtpUser,
|
|
|
|
pass: sails.config.custom.smtpPassword,
|
|
|
|
},
|
|
|
|
});
|
2024-03-22 00:14:09 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
getTransporter() {
|
|
|
|
return transporter;
|
|
|
|
},
|
|
|
|
|
|
|
|
isActive() {
|
|
|
|
return transporter !== null;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|