Question

Send email with nodemailer, 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: "user@gmail.com",
    pass: " ********* "
  }
});

transporter.sendMail(mailOptions, (err, info) => {
      if(err){
        console.log(err);
        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.

Thanks!


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.