As an application developer, how often we sense the need of a service that would send e-mails to specified or subscribed email ids? Even if there is no real need, we still fantasize about it while developing a pet-project or an app for fun, don't we 😁? In this article, I am going to explain the simple steps to send emails from your node.js app. At the end of it, we will be able to schedule and send e-mails. Not only that, we will be creating a REST API to post required details to a node.js app for sending emails. TL;DR Here is the working app You can find the code from my GitHub Repo: Test REST app for Sending e-mails Setting the stage is a super cool module for Node.js application to allow email sending so easily. Install it using Nodemailer npm npm install nodemailer --save Import in your .js (app.js, email.js whatever) file: Nodemailer nodemailer = ( ); let require 'nodemailer' Next, follow these three simple steps to get things working: Setup a message option: This is to tell is sending message to ? Nodemailer who what whom mailOptions = { : , : , : , : }; let from '<FROM_EMAIL_ADDRESS>' to '<TO_EMAIL_ADDRESS>' subject 'Email from Node-App: A Test Message!' text 'Some content to send' 👉 Note: The `to` property above can have multiple email ids separated by commas(,). Create a `Nodemailer` *transporter* using either SMTP(this is default) or [some other transport](https://nodemailer.com/transports/) mechanism transporter = nodemailer.createTransport({ : , : { : , : } }); let service 'gmail' auth user '<FROM_EMAIL_ADDRESS>' pass '<FROM_EMAIL_PASSWORD>' 👉 Note: In the above example, the `service` is mentioned as `gmail`. This is just an example. You can specify the name of the e-mail services you want to actually use. Use `sendMail()` method of your previously created transporter to deliver the message. transporter.sendMail(mailOptions, { (error) { .log(error); } { .log( + info.response); } }); ( ) function error, info if console else console 'Email sent: ' That's all, you are done. Now we have everything required to send e-mail from this node.js app. Hang on a Minute, We can schedule it! Yeah, right! The real power of this app comes with the fact that, you will be able to schedule the emails like, Send now Send everyday at 7p.m.(19:00 hrs), like a daily-digest Send every 30 minutes. Send on 29th Feb! ... many many more desired ways You guessed it right, we need something like a cron job and for that we will be using a node module called, . node-cron First install it. node install node-cron --save Import and schedule a task node-cron cron = ( ); cron.schedule( , () => { .log( ); }); let require 'node-cron' '* * * * *' console 'running a task every minute' 👉 Note: You can read about several cron schedule patterns . In the above example, we have scheduled a simple console log in every minute. here Here is the combined code where I am scheduling the e-mail to send every minute: cron = ( ); nodemailer = ( ); mailOptions = { : , : , : , : }; transporter = nodemailer.createTransport({ : , : { : , : } }); cron.schedule( , () => { transporter.sendMail(mailOptions, { (error) { .log(error); } { .log( + info.response); } }); }); let require 'node-cron' let require 'nodemailer' // e-mail message options let 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 service 'gmail' auth user '<FROM_EMAIL_ADDRESS>' pass '<FROM_EMAIL_PASSWORD>' '* * * * *' // Send e-mail ( ) function error, info if console else console 'Email sent: ' TADAAA, Done! REST API to Schedule and Send e-mail Well, this is an optional part for you, if your are not interested in creating a REST API for the purpose of Scheduling and Sending e-mails. In case you mind, we can do it in a minute using . I have posted an article on . Please take a quick look. sails.js How to Deploy your Sails.js app on Heroku and live longer Create a route in file of your sails.js app routes.js : 'post /api/sendemail' 'EmailController.sendEmail' Create an with method. This method should have the code discussed above for scheduling and sending email. EmailController sendEmail Wow, that was quick, isn't it? 👉 Note: With sails.js, you can also use other cron libraries like as well. The details can be found . sails-hook-cron here 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, from a node.js ap . After all, 😊😊😊 Scheduling and Sending e-mails Sharing is Caring....!!