I have a node.js application that sends email using nodemailer. It is working fine from localhost but when I try it from server I can't receive any mail.
Since, other activities of application are working fine means I assumed nodemailer is installed properly on server. I tried on both ways using host as my server and using gmail as on of the services. Here, is what I tried last time. This also works fine on local host. But, I don't get any response when I put this on server.
I have nodemailer's configuration as:
const output = `
<h3>Limit Details</h3>
<p>Admin has added ${limit} quota(s) to ${username}.</p>
`;
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
service: 'gmail',
port: 25,
secure: false, // true for 465, false for other ports
auth: {
user: '<gmail>',
pass: '<password>'
}
});
// setup email data with unicode symbols
let mailOptions = {
from: '"Sender" <sender gmail>', // sender address
to: '<receiver gmail>', // list of receivers
subject: 'Quota added information.', // Subject line
html: output // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
});
For testing, I have consoled messageId and Preview Url So, from where I can view this console message in cpanel? How can I view such consoled stuffs from my application in cpanel??
Unfortunately there is no easy way to access node's logs on a cpanel server as far as I know. What I usually do is I set up log4js to write logs to a file:
const log4js = require('log4js');
log4js.configure({
appenders: { everything: { type: 'file', filename: 'logs.log' } },
categories: { default: { appenders: ['everything'], level: 'ALL' } }
});
const logger = log4js.getLogger();
Then you can make logs with:
logger.debug('log message');
You can also serve the log file with the server:
app.get('/log', (req, res) => {
res.sendFile(path.join(__dirname + '/logs.log'));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With