Search code examples
shared-hostingnodemailer

Send email using Nodemailer with GoDaddy hosted email


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?


Solution

  • 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);
            });