whenever i run the code I'm getting the error " Error: Greeting never received at SMTPConnection._formatError...."
function automatedMailSender(req,res){
var mailOptions = {
from: "abc <abc@test.com>", // sender address
to: 'nit@test.com', // list of receivers
subject: 'Hello ', // Subject line
text: 'Hello world ?', // plain text body
html: '<b>Hello world ?</b>' // html body
};
var mailer=nodemailer.createTransport({
host: 'mail.test.com',
port: 465,
secure: false, // secure:true for port 465, secure:false for port 587
auth: {
user: 'mymail@test.com',
pass: '1234'
}
});
mailer.sendMail(mailOptions, (error, response)=>{
if(error){
console.log('mail not sent \n',error);
}
else{
console.log("Message sent: " ,response.message);
}
});
}
I'm I doing something wrong in the code.
If you are using Gmail to send mails then try this.
Allow less secure apps to connect to Gmail.
Try something like that, it work perfectly for me:
The answer in right in your code
The value for "secure" should be true for port 465
fixed it by using the above code in mailer variable. Thanks guys