Send email with nodemailer, centOS

April 20, 2016 539 views
Node.js Linux Commands CentOS

Hello everyone,

I have a express.js app installed in a centOS server. I have a code that in my local environment works fine, but in the centOS doesn't work.

Here is the code:

const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
  service: 'gmail',
  options: {
    debug: true
  auth: {
    user: "",
    pass: " ********* "


transporter.sendMail(mailOptions, (err, info) => {
        return res.render('index.html', {HOME: req.home, mensagem: 'Erro no envio de mensagem', erro: 1});
      return res.render('index.html', {HOME: req.home, mensagem: 'Email enviado com sucesso', erro: 0});

It's a nodemailer module from npm. I tried to check with there is any mistake on my SMTP port, but i didn't find anything.


1 Answer

Without more information it is difficult to know what the underlying cause of this issue is. I would recommend reviewing your logs. One thing I have seen before is that gmail will not always allow a connection via SMTP from a new machine without requiring you to log in with a web browser.

For a service that needs to send email via SMTP I would recommend using a 3rd party service like SendGrid (they allow up to 12k monthly email sends for free) to ensure delivery and ease the setup process.

Have another answer? Share your knowledge.