Introduction :

The idea of this tutorial is to explain how to send emails using Nodemailer with MimePost SMTP. We will focus mainly on SMTP way of sending mail. Besides, this tutorial will help you prepare and test email messages to send out with your Node.js application.

Requirements

  • Node.js v6.0.0 or newer. that’s it.
  • Create an account on MimePost to get free SMTP

Click here for the reference to getting start with Mimepost SMTP

What is Nodemailer ?

Nodemailer is a module for Node.js applications to allow easy as cake email sending. The project got started back in 2010 when there was no sane option to send email messages, today it is the solution most Node.js users turn to by default.

What is MimePost ?

MimePost  provides Secure SMTP & Email API Service with Inject, Process and Deliver. Nothing gets stored.

Security can be compromised, so as the data. But, what if there is no DATA at all to hack. MimePost introduces NoData Communication Cloud (NDCC), a cloud communication platform where all your email communication and user-related data always remains in transit, and nothing gets stored on disk.
this slowpoke moves

First install Nodemailer in your node application.

npm install --save nodemailer

After installation create a file index.js and write the below code.

const nodemailer = require("nodemailer");

async function main() {

  let transporter = nodemailer.createTransport({
    host: "smtp.mimepost.com",
    port: 2525,
    secure: false, // true for 465, false for other ports
    auth: {
      user: "YOUR_MIMEPOST_SMTP_USERNAME", // generated ethereal user
      pass: "YOUR_MIMEPOST_SMTP_KEY", // generated ethereal password
    },
    tls: {rejectUnauthorized: false}
  });

  // send mail with defined transport object
  let info = await transporter.sendMail({
    from: '"Fred Foo 👻" <foo@example.com>', // sender address
    to: "example@example.com", // list of receivers
    subject: "Hello ✔", // Subject line
    text: "Hello world?", // plain text body
    html: "<b>Hello world?</b>", // html body
  });

  console.log("Message sent: %s", info.messageId);
}

main().catch(console.error);

Enter the below options in above code :-

from : The sender of the email

to : The recipient of the email

subject : the subject of the email

html : all the magic happens here

"YOUR_MIMEPOST_SMTP_USERNAME" :  Mimepost SMTP username

YOUR_MIMEPOST_SMTP_KEY : Mimepost SMTP key

this slowpoke moves

Now lets run the script with the following command :-

node index.js

expected output  :

Message sent: a06ceccb-feb9-7ded-0218-b7b7b6a572fc@cieberry.com

And that’s how we send emails in nodejs using nodemailer with Mimepost SMTP.