Wednesday, June 11, 2014

Send email use Node.js on BlueMix

There are many ways to send eamil use node.js.Today I will introduce three ways to send email.

1.Nodemailer is an easy to use module to send e-mails with Node.JS (using SMTP or sendmail or Amazon SES or even your own method) and is unicode friendly - You can use any characters you like.

The whole development is very easy.
a)Install Nodemailer
> npm install nodemailer
b)Write below code
var nodemailer = require("nodemailer");

var smtpTransport = nodemailer.createTransport("SMTP",{
   service: "Gmail",
   auth: {
       user: "",
       pass: "XXX"

var mail = {
    from: "",
    to: "",
    subject: "Send Email Using Node.js",
    text: "Node.js New world for me",
    html: "<b>Node.js New world for me</b>"

smtpTransport.sendMail(mail, function(error, response){
        console.log("Message sent: " + response.message);


c) In node.js enviroment run nodeemail.js,you will see the email has been sent.

d)You can install it from npm. Add a dependency to your package.json and run npm install
package.json contents:
"dependencies": {
   "nodemailer": "0.3.29"

2. Since first way we need to use smtp and also need authenciation,sometimes we don;t have smtp server provided,so we need to use 'sendmail module to handle it .The code is more easy.

sendmail = require('sendmail')();

    from: '',
    to: '',
    subject: 'test sendmail',
    type: 'text/html',
    content: '<h3>hello</h3><p>Hey guys</p>
  }, function(err, reply) {
    console.log(err && err.stack);
Also you can reference this open source code at github.

3.Using SendGrid service,you can reference below link.


  1. You need to remove the `"SMTP",` from the example above to make it work with nodemailer v2.

  2. There is a chance you are eligible for a complimentary $1,000 Amazon Gift Card.

  3. BlueHost is one of the best web-hosting provider with plans for any hosting requirements.