Send email comfortably using Mailman in nodejs


Some information about sending email in nodejs so in this post we will discuss about a new module called Mailman, where you can send emails in a comfortable way via models. It is developed by Vadim Demedes, you can find the source code here.

PC : https://www.npmjs.com/package/mailman

The features of mailman includes :

  • It uses nodemailer to send out emails and uses consolidate.js to render email templates. As it uses consolidate.js thus supports a lot of templates.
  • It is clean, simple and lightweight code base.
  • It is very comfortable as it is ActiveMailer-inspired API

How to install mailman

npm install mailman –save

How to Configure mailman

//At first you have to include in your application
var Mailman = require(‘mailman’);

// You have to specify the folder where are the email templates
Mailman.options.views.path = ‘path_to_views/’;

//Then you need to configure your email account from which you will be sending mails
Mailman.configure(‘gmail’, { user : ‘your_user_name@gmail.com’, password: ‘your_password’ });

//Then we will configure the smtp host
Mailman.configure({
host: ‘smtp.gmail.com’,
port: 465,
secure: true,
auth: { user : ‘your_user_name@gmail.com’, password: ‘your_password’ }
});

//we can even configure the 3rd-party transport like this
Mailman.configure(transport);

How to Send Email

var UserMailer = Mailman.mailre.extend({
name: ‘your_name’,
from: ‘your_email_address’,
subject: ‘Test’,
hello: function () {
this.full_name = ‘Name_To_Send’,
this.currentDate = new Date();
}
});

Then,

var mail;
mail = new UserMailer({to: ‘whom_to_send_email_address’ }).hello();
yield mail.deliver();

Happy Coding 🙂
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s