Send email using Nodemailer with GoDaddy hosted email
Asked Answered
S

7

10

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?

Sounding answered 30/6, 2017 at 19:17 Comment(0)
P
32

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);
        });
Propose answered 12/11, 2019 at 23:55 Comment(8)
This works like charm. Well after an hour I landed here. Thanks ! Just for future folk, this works with AWS Lamda too.Emilie
@BharatBiswal, your code is working on localhost. But when I run it from the digital ocean server, it is showing an error that the connection is timeout.Presentiment
Please ping smtpout.secureserver.net from digital ocean server.Propose
As per today (28th July, 2021) this is still working like a charm! Thank you!!!!Gony
Note on this, if you do it this way, you'll only be able to send 25 emails a day. See https://mcmap.net/q/1036485/-send-email-using-nodemailer-with-godaddy-hosted-email for an answer that works. However, after doing this, you'll have to call GoDaddy support so they can enable SMTP for you since otherwise you'll run into the error: SmtpClientAuthentication is disabled for the Tenant.Philan
@AbhinavKumar - its not working for me can you help please?Hollenbeck
This worked perfectly with Godaddy Professional Email. Used exact code mentioned above, No need to do any other things!Punctate
But unfortunately, sent mails are not available in mailbox. So probably need to store all mail in DB.Punctate
R
10

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" 
    }
});
Regurgitate answered 5/9, 2017 at 13:53 Comment(1)
Worked for me. but replace "secureConnection" with "secure"Missile
D
9

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: "[email protected]",
        pass: "password"
    }
};
let transporter = nodemailer.createTransport(mailerConfig);

let mailOptions = {
    from: mailerConfig.auth.user,
    to: '[email protected]',
    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');
    }
});
Debera answered 23/4, 2019 at 15:43 Comment(4)
Should no longer be flagged as solution as it has become obsolete. See other solutions provided hereGony
this works great, the only thing is you will run into the error: ` SmtpClientAuthentication is disabled for the Tenant. ` at which point you have to call GoDaddy support, and they will enable SMTP relay for you.Philan
Thanks Evan. It worked like Magic. I called Godaddy, and asked them to "Enable SMTP relay for the email address on that domain". 5mins is all it took.Kynan
Many thanks Stanton it works greatRoentgen
K
0

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);
});
Kocher answered 11/8, 2020 at 6:36 Comment(2)
Thanks a lot. I was trying to figure this out for past two days nothing worked. I tried to put the IP address of my shared host but that did not work. Where did you find this if you can share ?Zebu
Error messages were helpful to chase the fix. Error was saying my host (I was putting my domain name) didn't match to that the host machine's name. That was enough hint that I needed to use the output of "hostname". Port 25 is coming from godaddy blog posts about the same issue.Kocher
A
0

I could solve the problem by using this code and some points that I brought them after codes:

  const smtpTransport = nodemailer.createTransport({
  host: "smtp.office365.com",  
  secure: false,
  port: 587,
  auth : {
    user : '[email protected]',
    pass : 'Password'
  }
});

const mailOptions = {
  to: 'target-mail@',
  subject: 'Test 01',
  html: 'Body',
  from : '[email protected]'
};
await smtpTransport.sendMail(mailOptions);
  • Don't forget to use 'from' attribute in mailOptions
  • Don't use ',' in your 'from' attribute
Allottee answered 3/11, 2022 at 15:25 Comment(0)
B
0

For me, the solution for production shared hosting server was completely different than for testing.

It seems no authentication or credentials are required for it to work.

I created this code from this document describing how to use an SMTP relay server. You can use this with nodemailer. GoDaddy support told me I couldn't but I don't think they know about third party tools.

https://au.godaddy.com/help/send-form-mail-using-an-smtp-relay-server-953

    async function main() {
    
      // create reusable transporter object using the default SMTP transport
      let transporter = nodemailer.createTransport({
        host: 'localhost', //use localhost for linux cPanel hosting
        port: 25,
        secure: false, 
      // no need for authentication
        tls: {
            rejectUnauthorized: false
        }
      });
    
      // send mail with defined transport object
      let info = await transporter.sendMail({
        to: "[email protected]", // list of receivers
        subject: `New Message from ${name}`, // Subject line
        text: `yourtext`, // plain text body
        html: `your text in html`, // html body
        headers: {
          priority: 'high'
        },
        from: "[email protected]" // sender address
      });
    
// send success page if successful
      if (res.statusCode === 200) {
        res.sendFile(path.join(__dirname, 'views/success.ejs'))
      }
    
      console.log("Message sent: %s", info.messageId, res.statusCode);
    
    }
    
    main().catch(console.error);
Beecher answered 12/2, 2023 at 12:3 Comment(0)
E
0

Tested on 16-03-2023:

let transporter = nodemailer.createTransport({
  host: 'yourwebsite.com',
  port: 465,
  auth: {
    user: '[email protected]',
    pass: 'yourEmailPassword'
  }
});

This worked for emails created under Email Accounts on cPanel.

Earwax answered 16/3, 2023 at 6:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.