visit
TL;DR
Here is the working appis a super cool module for Node.js application to allow email sending so easily. Install it using npm
npm install nodemailer --save
Import Nodemailer in your .js (app.js, email.js whatever) file:
let nodemailer = require('nodemailer');
let mailOptions = {
from: '<FROM_EMAIL_ADDRESS>',
to: '<TO_EMAIL_ADDRESS>',
subject: 'Email from Node-App: A Test Message!',
text: 'Some content to send'
};
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '<FROM_EMAIL_ADDRESS>',
pass: '<FROM_EMAIL_PASSWORD>'
}
});
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
node install node-cron --save
let cron = require('node-cron');
cron.schedule('* * * * *', () => {
console.log('running a task every minute');
});
let cron = require('node-cron');
let nodemailer = require('nodemailer');
// e-mail message options
let mailOptions = {
from: '<FROM_EMAIL_ADDRESS>',
to: '<TO_EMAIL_ADDRESS>',
subject: 'Email from Node-App: A Test Message!',
text: 'Some content to send'
};
// e-mail transport configuration
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '<FROM_EMAIL_ADDRESS>',
pass: '<FROM_EMAIL_PASSWORD>'
}
});
cron.schedule('* * * * *', () => {
// Send e-mail
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
});
'post /api/sendemail': 'EmailController.sendEmail'
👉 Note: With sails.js, you can also use other cron libraries like sails-hook-cron as well. The details can be found .
Let me know if this was useful to you.Please feel free to comment on the alternate ways and methods you may be using for serving the same purpose, i.e, Scheduling and Sending e-mails from a node.js ap . After all, Sharing is Caring....!! 😊😊😊