This is on a MEAN stack project on a VPS. Server OS: Ubuntu 20.04
Problem: Emails are getting sent using gmail or other SMTP credentials. But when a specific domain email credentials are used. The email doesn’t go.
The below is the mail config being used.
"mailServerOptions": {
"pool": true,
"host": "xxx.xxx.xxx.xxx",
"port": 465,
"secure": true,
"auth": {
"user": "[email protected]",
"pass": "xxxxxxx"
},
"tls":{
"rejectUnauthorized":false
}
}
The sendEmail method:
async function sendEmail({ to, subject, html}) {
const copyMailServerOptions = JSON.parse(JSON.stringify(config.mailServerOptions));
const transporter = nodemailer.createTransport(copyMailServerOptions);
let sendEmail = true;
const xFrom = copyMailServerOptions.auth.user
transporter.verify(function(error, success) {
if (error) {
sendEmail = false;
console.log('email transporter error', error);
throw 'email transporter error: ' + error
} else {
try{
const result = transporter.sendMail({ from: xFrom, to, subject, html });
} catch(error){
console.log('transporter.sendMail to: ' + to + ' - Error: ' + error)
}
}
});
}
Checked host IP address. Its correct.
I have tried
- by removing port and secure properties from the above config object – email doesn’t go.
port: 587, secure: false
– email doesn’t go.- using
host: "mail.specificDomain.com"
– email doesn’t go. - using another domain email credentials – email goes.
- gmail options – email goes.
This config was being used in the past and it used to work a few months ago. Now needed to use these credentials again and realised it stopped working.
What could be possibly wrong?