Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: '[email protected]',
    pass: 'mypassword'
  }
});

var mailOptions = {
  from: '[email protected]',
  to: '[email protected]',
  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?

like image 489
Dustin Spengler Avatar asked Nov 28 '22 02:11

Dustin Spengler


2 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: `[email protected]`,
            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);
        });
like image 198
Bharat Biswal Avatar answered Dec 26 '22 08:12

Bharat Biswal


you should make some changes in your transporter:

 var smtpTrans = nodeMailer.createTransport({    
    service: 'Godaddy',
    host: "smtpout.secureserver.net",  
    secureConnection: true,
    port: 465,

    auth: {
        user: "username",
        pass: "password" 
    }
});
like image 42
tirmey Avatar answered Dec 26 '22 07:12

tirmey