Send email with nodemailer, centOS

Posted April 20, 2016 6k views
CentOSNode.jsLinux Commands

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.


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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.