Bulk email sending usiing node.js

16.4k views Asked by At

I am trying to make a small dashboard where i can send bulk email using my own SMTP servers. I want to use node for this, can anyone guide from where to start i want to send mails from different SMTP servers.

1

There are 1 answers

1
rsp On BEST ANSWER

A most common way to send email in Node is using Nodemailer. It has an excellent documentation.

You can use it to send email using any SMTP servers and there are a lot of preconfigured ways to send using Gmail or other specialized transports.

The available transports are - from the README:

  • nodemailer-mailgun-transport for sending messages through Mailgun's Web API
  • nodemailer-mandrill-transport for sending messages through Mandrill's Web API
  • nodemailer-pickup-transport for storing messages to pickup folders
  • nodemailer-sailthru-transport for sending messages through Sailthru's Web API
  • nodemailer-sendgrid-transport for sending messages through SendGrid's Web API
  • nodemailer-sendmail-transport for piping messages to the sendmail command
  • nodemailer-ses-transport for sending messages to AWS SES
  • nodemailer-sparkpost-transport for sending messages through SparkPost's Web API
  • nodemailer-stub-transport is just for returning messages, most probably for testing purposes
  • nodemailer-wellknown for sending messages through one of those many supported services
  • nodemailer-postmark-transport for sending messages through Postmark's Web API
  • add yours (see transport api documentation here)

Here is a simple usage example in the Nodemailer GitHub repo

var nodemailer = require('nodemailer');

// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport('smtps://user%40gmail.com:[email protected]');

// setup e-mail data with unicode symbols
var mailOptions = {
    from: '"Fred Foo " <[email protected]>', // sender address
    to: '[email protected], [email protected]', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world ', // plaintext body
    html: '<b>Hello world </b>' // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
    if(error){
        return console.log(error);
    }
    console.log('Message sent: ' + info.response);
});

See:

For bulk mailing it's much better to use a service like Mailgun or Mandrill because doing bulk mailing yourself using SMTP it's a lot of hassle to make sure that your emails are going through spam filters and that you are not blacklisted for sending too much email, that you don't exceed any limits of your ISP etc. Sending emails is more complicated than people usually think and with prices like $0.0001 per email in Mailgun it's also dirt cheap.