[ACCEPTED]-Sending emails in Node.js?-email

Accepted answer
Score: 162

Nodemailer is basically a module that gives 13 you the ability to easily send emails when 12 programming in Node.js. There are some great 11 examples of how to use the Nodemailer module 10 at http://www.nodemailer.com/. The full instructions about how to 9 install and use the basic functionality 8 of Nodemailer is included in this link.

I 7 personally had trouble installing Nodemailer 6 using npm, so I just downloaded the source. There 5 are instructions for both the npm install 4 and downloading the source.

This is a very 3 simple module to use and I would recommend 2 it to anyone wanting to send emails using 1 Node.js. Good luck!

Score: 142

node-email-templates is a much better option: https://github.com/niftylettuce/node-email-templates

it 1 has support for windows as well

Score: 65

Check out emailjs

After wasting lots of time on 11 trying to make nodemailer work with large 10 attachments, found emailjs and happy ever 9 since.

It supports sending files by using 8 normal File objects, and not huge Buffers 7 as nodemailer requires. Means that you can 6 link it to, f.e., formidable to pass the 5 attachments from an html form to the mailer. It 4 also supports queueing..

All in all, no idea 3 why nodejitsu ppl chose nodemailer to base 2 their version on, emailjs is just much more 1 advanced.

Score: 57

Complete Code to send Email Using nodemailer 1 Module

var mailer = require("nodemailer");

// Use Smtp Protocol to send Email
var smtpTransport = mailer.createTransport("SMTP",{
    service: "Gmail",
    auth: {
        user: "gmail_id@gmail.com",
        pass: "gmail_password"
    }
});

var mail = {
    from: "Yashwant Chavan <from@gmail.com>",
    to: "to@gmail.com",
    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){
    if(error){
        console.log(error);
    }else{
        console.log("Message sent: " + response.message);
    }

    smtpTransport.close();
});
Score: 25

@JimBastard's accepted answer appears to 8 be dated, I had a look and that mailer lib 7 hasn't been touched in over 7 months, has 6 several bugs listed, and is no longer registered 5 in npm.

nodemailer certainly looks like the best option, however 4 the url provided in other answers on this 3 thread are all 404'ing.

nodemailer claims 2 to support easy plugins into gmail, hotmail, etc. and 1 also has really beautiful documentation.

Score: 9

You could always use AlphaMail (disclosure: I'm one of the developers behind it).

Just install with 7 NPM:

npm install alphamail

Sign up for a AlphaMail account. Get a 6 token, and then you can start sending with 5 the AlphaMail service.

var alphamail = require('alphamail');

var emailService = new alphamail.EmailService()
    .setServiceUrl('http://api.amail.io/v1/')
    .setApiToken('YOUR-ACCOUNT-API-TOKEN-HERE');

var person = {
    id: 1234,
    userName: "jdoe75",
    name: {
        first: "John",
        last: "Doe"
    },
    dateOfBirth: 1975
};

emailService.queue(new alphamail.EmailMessagePayload()
    .setProjectId(12345) // ID of your AlphaMail project (determines template, options, etc)
    .setSender(new alphamail.EmailContact("Sender Company Name", "from@example.com"))
    .setReceiver(new alphamail.EmailContact("John Doe", "to@example.org"))
    .setBodyObject(person) // Any serializable object
);

And in the AlphaMail 4 GUI (Dashboard) you'll be able to edit the template 3 with the data you sent:

<html>
    <body>
        <b>Name:</b> <# payload.name.last " " payload.name.first #><br>
        <b>Date of Birth:</b> <# payload.dateOfBirth #><br>

        <# if (payload.id != null) { #>
            <a href="http://company.com/sign-up">Sign Up Free!</a>
        <# } else { #>
            <a href="http://company.com/login?username=<# urlencode(payload.userName) #>">Sign In</a>
        <# } #>
    </body>
</html>

The templates are 2 written in Comlang, it's a simple template language 1 specifically designed for emails.

Score: 8

Mature, simple to use and has lots of features 2 if simple isn't enought: Nodemailer: https://github.com/andris9/nodemailer (note 1 correct url!)

Score: 5

Nodemailer Module is the simplest way to 2 send emails in node.js.

Try this sample example 1 form: http://www.tutorialindustry.com/nodejs-mail-tutorial-using-nodemailer-module

Additional Info: http://www.nodemailer.com/

Score: 3

npm has a few packages, but none have reached 1 1.0 yet. Best picks from npm list mail:

email@0.2.2
mail@0.1.1
mailer@0.3.0
Score: 3

You definitely want to use https://github.com/niftylettuce/node-email-templates since it supports 2 nodemailer/postmarkapp and has beautiful 1 async email template support built-in.

Score: 2

campaign is a comprehensive solution for sending 7 emails in Node, and it comes with a very 6 simple API.

You instance it like this.

var client = require('campaign')({
  from: 'you@gmail.com'
});

To 5 send emails, you can use Mandrill, which is free 4 and awesome. Just set your API key, like 3 this:

process.env.MANDRILL_APIKEY = '<your api key>';

(if you want to send emails using another provider, check the docs)

Then, when you want to send an email, you 2 can do it like this:

client.sendString('<p>{{something}}</p>', {
  to: ['someone@gmail.com', 'someone.else@gmail.com'],
  subject: 'Some Subject',
  preview': 'The first line',
  something: 'this is what replaces that thing in the template'
}, done);

The GitHub repo has 1 pretty extensive documentation.

More Related questions