Why can't I send emails in Nodejs, Ubuntu 16.04 using nodemailer.

Posted July 30, 2017 8k views
Node.jsUbuntu 16.04

I am using nodemailer to send mails, I was available to send mails through it in but I can’t in my droplet with Ubuntu 16.04, here is my actual code to send emails:

var sendEmail = function(subjectText, bodyText) {

  var nodemailer = require('nodemailer');

  var transporter = nodemailer.createTransport({
    service: 'gmail',
    port: 443,
    options: {
      debug: true,
    auth: {
        user: '',
        pass: '****'

  // verify connection configuration
  transporter.verify(function(error, success) {
     if (error) {
     } else {
          console.log('Server is ready to take our messages');

  var mailOptions = {
    from: '',
    to: '',
    subject: subjectText,
    text: bodyText

  transporter.sendMail(mailOptions, function(error, info) {
    if(error) {
        console.log('Email couldnt be sent.\n', error.response);
    } else {
        console.log('Email sent: ' + info.response);

module.exports = {
  sendEmail: sendEmail

I have already tried shutting down the firewall, what can I do to make this work? Do you know another alternative to send mails via node'js in Digital Ocean servers?

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

Hi @michaelszer

If your account with DigitalOcean is new, then sometimes all SMTP is blocked.
You need to create a ticket with Support via the control panel and ask to get SMTP unblocked.