Report this

What is the reason for this report?

Send email with nodemailer, centOS

Posted on April 20, 2016

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!



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!

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.

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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.