0

I have been trying to send an email with Nodemailer from an email on Cpanel. When I was using Gmail, it was working fine but now I have switched to Cpanel (where a business mailbox is hosted), I don't get an error, just no email is sent. Here is my Nodemailer code:

var nodemailer = require("nodemailer")
var smtpTransport = require("nodemailer-smtp-transport")

var transporterDetails = smtpTransport({
    host: 'my host',
    port: 465,
    secure: true,
    auth: {
        user: "example@emample.co.uk",
        pass: "password123"
    },
    maxConnections: 5,
    maxMessages: 10
})

module.exports = {
    queryEmail: function(name, number, email, comments){
        var transporter = nodemailer.createTransport(transporterDetails);
        var mailOptions = {
            from: 'example@example.co.uk',
            to: 'example@example.com',
            subject: "New Email",
            html: "<p> An Email.</p>"
        };
        transporter.sendMail(mailOptions);
    },
 ...

I have taken the host details from the Cpanel mailbox which looks like this:

Cpanel Mailbox Config

I have tried a number of different configurations based on the Cpanel mailbox config but nothing seems to work (I have tried it without the SMTP block and just passing the object straight in the create transporterFunction). Without the SMTP block I get this error:

(node:14224) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 12): Error: getaddrinfo ENOTFOUND aventador.websitewelcome.com hostname.websitehello.com:465

Anything look wrong with the above code which might be stopping it?

Haych
  • 932
  • 13
  • 36

1 Answers1

0

If the app is hosted on the cPanel server, you could use for host: 'my host', localhost instead of your actual dns record or hostname since you connect to the mail server locally. Give it a try.

Bogdan Stoica
  • 4,349
  • 2
  • 23
  • 38
  • Unfortunately, it's not hosted on the same cPanel server. – Haych Aug 11 '17 at 10:12
  • Well are you sure that email is working using an email client with the exact same settings?! – Bogdan Stoica Aug 11 '17 at 12:11
  • I have put what I have assumed to be the correct settings but I am hoping someone with Cpanel experience could tell me otherwise or see something wrong with the code that I have. – Haych Aug 11 '17 at 13:10
  • Honestly I don't think it's a cpanel related issue but rather a DNS issues or anything related to that because of `Error: getaddrinfo ENOTFOUND`. This link might help you: https://stackoverflow.com/questions/17690803/node-js-getaddrinfo-enotfound – Bogdan Stoica Aug 11 '17 at 13:32