Closed MANTENN closed 5 years ago
Typo transporter
is supposed to set transport
Use this code this will work finely
var transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure:false,
auth: {
user: '*',
pass: process.env.PASSWORD
}
});
var mailOptions = {
from: '**',
to: **,
subject: 'Thankyou for contacting!',
text: Hii ${req.body.username} thanks for contacting. I will touch you soon!
};
var mailOptionsSender = {
from: '*',
to: '****',
subject: 'Someone Wants to connect With you !',
text: Hello ${req.body.username} wants to connect with you please contact him to further query!
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
transporter.sendMail(mailOptionsSender, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
}
});
This worked for me using gmail smtp
const nodemailer = require('nodemailer');
const msg = { from: "example@gmail.com", to: "receiver@gmail.com", subject: "Nodemailer", text: "Testing out" };
nodemailer.createTransport({ service: 'gmail', auth: { user: "example@gmail.com", pass: "**" //This should be a password generated by google App password }, port: 465, host: 'smtp.gmail.com' })
.sendMail(msg , (err)=>{ if (err) { return console.log('Error occurs', err); }else{ return console.log('Email Sent'); } })
My setup
Package.json