Send email using Nodemailer with GoDaddy hosted email

Viewed 12620

I am trying to send an email using nodemailer and a custom email address configured through GoDaddy. Here is a screen shot of the "custom configurations" page in c-panel: enter image description here

and my code:

const nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
  service: 'Godaddy',
  secureConnection: false,
  auth: {
    user: 'info@mywebsite.com',
    pass: 'mypassword'
  }
});

var mailOptions = {
  from: 'info@mywebsite.com',
  to: 'otheremail@gmail.com',
  subject: 'Sending Email using Node.js',
  text: 'That was easy!',
  html: '<h1>Welcome</h1><p>That was easy!</p>'
};

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

and my error log:

{ Error: connect EHOSTUNREACH 173.201.192.101:25
    at Object.exports._errnoException (util.js:1012:11)
    at exports._exceptionWithHostPort (util.js:1035:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
    code: 'ECONNECTION',
    errno: 'EHOSTUNREACH',
    syscall: 'connect',
    address: '173.201.192.101',
    port: 25,
    command: 'CONN' }

I've tried changing the port number, making it secure vs non-ssl, using my website address as the host, and pretty much everything else I can think of. I have successfully sent an email from the godaddy email using one of the webmail clients. Has anyone else ever encountered this or have recommendations on things to try?

5 Answers

I am trying to send emails using nodemailer from Google Cloud Function using GoDaddy SMTP settings. I do not have Office365 enabled on my GoDaddy hosting. None of the above options worked for me today (12 November 2019). TLS need to be enabled.

I had to use the following configuration:

const mailTransport = nodemailer.createTransport({    
    host: "smtpout.secureserver.net",  
    secure: true,
    secureConnection: false, // TLS requires secureConnection to be false
    tls: {
        ciphers:'SSLv3'
    },
    requireTLS:true,
    port: 465,
    debug: true,
    auth: {
        user: "put your godaddy hosted email here",
        pass: "put your email password here" 
    }
});

Then, I could send a test email as follows:

const mailOptions = {
            from: `put your godaddy hosted email here`,
            to: `bharat.biswal@gmail.com`,
            subject: `This is a Test Subject`,
            text: `Hi Bharat    

            Happy Halloween!

            If you need any help, please contact us.
            Thank You. And Welcome!

            Support Team
            `,

        };

mailTransport.sendMail(mailOptions).then(() => {
            console.log('Email sent successfully');
        }).catch((err) => {
            console.log('Failed to send email');
            console.error(err);
        });

I realize this is an old post, but just wanted to add to this since the GoDaddy SMTP server has changed, just in case someone else comes across this and has the same problem I had. The answer by @tirmey did not work for me, but this did.

let nodemailer = require('nodemailer');

let mailerConfig = {    
    host: "smtp.office365.com",  
    secureConnection: true,
    port: 587,
    auth: {
        user: "username@email.com",
        pass: "password"
    }
};
let transporter = nodemailer.createTransport(mailerConfig);

let mailOptions = {
    from: mailerConfig.auth.user,
    to: 'SomePerson@email.com',
    subject: 'Some Subject',
    html: `<body>` +
        `<p>Hey Dude</p>` +
        `</body>`
};

transporter.sendMail(mailOptions, function (error) {
    if (error) {
        console.log('error:', error);
    } else {
        console.log('good');
    }
});

Solutions proposed above seem no longer valid, none of them worked for me. Following solution works for me:

const nodemailer = require('nodemailer');
const os = require('os');

let mailerConfig = {
    host: os.hostname(),
    port: 25,
};
let transporter = nodemailer.createTransport(mailerConfig);
transporter.sendMail({
    from: '<from>',
    to: '<to>',
    subject: '<subject>',
    text: '<text>'
}, (err, info) => {
    console.log(info);
    console.log(err);
});
Related