Some emails from Nodemailer are not reaching the clients - node.js

I was sending register verification emails through Nodemailer using the code below, and it turns out that some of my clients are either not receiving anything or the email goes to spam. Some other clients can receive the email normally. I asked Google Support but they said it is not possible that the same kind of emails goes to some users' spam folder and some other users' inbox folder. That's why I am confused here.
BTW, Google confirmed with me that the DKIM and other verifications are good. And the emails that are sent have arrived at those clients' mailboxes. But without their approval, Google doesn't know if the email is not actually there or is sent to the spam folder.
function registerEmailSender(firstName, lastName, email, uuid) {
console.log('registerEmailSender is triggered');
console.log('email: ', email);
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'info#mydomain.com', // generated ethereal user
pass: 'mypassword' // generated ethereal password
},
});
const html = `
Hi ` + firstName + `,<br>
<br>
Please click the link to active your account: https://example.com/sessions/email-verification/` + uuid + `<br>
<br>
Sincerely, <br>
My Team<br>
`
const mailOptions = {
from: 'My Email <info#mydomain.com>', // sender address
to: email, // list of receivers
subject: 'Happy to have you here', // Subject line
html: html
};
return transporter.sendMail(mailOptions, function (err, info) {
console.log('sendMail is triggered');
// if(err)
// console.log('Error occurs: ', err)
// else
// console.log('Email sent: ', info);
if(err) {
console.log('Error occurs: ', err)
}
else {
console.log('Email sent: ', info);
}
});
}

It turns out nodemailer is not very reliable due to it is not recognized as a 'trusted application' unless your server itself is trusted by Google. And that seems to be reducing your reputation and cause the email to be rejected.
Best solution I can find for now is to use some paid mailing service like Mailchimp. Just don't use Nodemailer if you don't have to.

Related

Receiving email from users by nodemailer

I am trying to receive email from users using nodemailer. The email will be sent from users email and received by my email. But all it doing is sending email from my email to my email though I set different email account for from and to. But when I revesre the email acounts and set from:myemail#example.com and to:usersemail#example.com this works fine. Why this is happening? How can I fix this so that I can receive emails from users? Here is the code:
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
service: "gmail",
secure: false,
auth: {
user: process.env.MY_EMAIL,
pass: process.env.MY_PASSWORD,
},
});
// Creating the email
let info = {
from: process.env.USERS_EMAIL,
to: process.env.MY_EMAIL,
subject: 'Demo message',
text: 'For clients with plaintext support only',
html: `
<p>This is a demo email</p>
`
};
//send the email
transporter.sendMail(info, function (err, info) {
if (err) {
console.log(err);
}
else{
console.log(info);
}
})

E-mail getting rejected sent by Nodemailer

I am trying to send an email which includes HTML content with the help of nodemailer-express-handlebars. Every time my mail gets blocked by the Gmail which can be checked in sender's Gmail sent-box whereas I got success msg from nodemailer
Email sent: 250 2.0.0 OK 1595608108 i66sm6757247pfc.12 - gsmtp
I am unable to understand why this happening as when I send a mail with text, it gets delivered.
NODEMAILER CODE
sendMail=(email)=>{
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'emailId',
pass: 'password'
}
});
transporter.use('compile',hbs({
viewEngine:{
partialsDir:"./views/",
defaultLayout: "",
layoutsDir: "",
},
viewPath:"./views/",
extName:'.hbs',
}))
var mailOptions = {
from: '<xyz#gmail.com>',
to: email,
subject: 'Your order has been placed successfully.',
template:'mail',
context:{
name:"XYZ",
address:"133"
}
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
}
It's recommended to use OAuth2 with NodeMailer and Gmail. Using the plain username and password might be what's causing you problems.

Use sendgrid from send emails with nodemailer appication gives following error?

use nodemailer and nodemailer-sendgrid-transport it show the following error
error:The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements
`const nodemailer=require('nodemailer');
const sendGridTranspoter=require('nodemailer-sendgrid-transport')
const transport=nodemailer.createTransport(sendGridTranspoter({
service: 'SendGrid',
auth:{
api_user:'myuser name',
api_key:'password'
}));
`
this is inside my sign up controller function
var email = {
from: 'sener email',
to: 'receiver valid email',
subject: 'shopMe',
text: 'successfully sign up',
html: '<b>Hello world</b>'
};
transport.sendMail (email, function(err, info){
if (err ){
console.log(err);
}
else {
console.log('Message sent: ' + info.response);
}
});
there are two possible ways,
1.allow less secure apps "on" in your google mail security
2.Go to sendgrid, click on marketing and after click senders , fillup the details and check it
You need to verify the mail that is the sender. I solved this problem in this way:
Go here:
Setting -> Sender Authentication -> Single Sender Verification -> Verify an Address
Example
After that, fill out the form on the right and complete the verification of the sender's mail.
You can read in more detail here.

nodemailer not sending and returning error

I'm trying to setup a simple contact form using nodemailer. All i'm trying to do is send an email to my email from the contact form. My email is "myemail#mac.com"
When I do my axios post I get an error in the data object saying: 550 5.7.0 From address is not one of your addresses. but yet the status:200 and statusText:"OK"
When I use the same from email as the icloud email "myemail#mac.com" then it works ? I dont see anything where it says you have to use the same from address as the service address ?
Axios post:
const request = axios.post('http://localhost:3002/send', {'name':John Doe,'email':meme#gmail.com'});
request.then((result)=>{
console.log("request = ", result);
});
Error message from console.log("request = ", result);
error:{
code:"EMESSAGE",
command:"DATA",
response:"550 5.7.0 From address is not one of your addresses.",
responseCode:550
}
nodemailer is my node.js
const transporter = nodemailer.createTransport({
service: "iCloud",
auth: {
user: "myemail#mac.com",
pass: "myemailpassword"
}
})
app.use('/send', function(req, res){
var message = {
from: req.body.email,
to: 'myemail#mac.com',
subject: 'Message From Portfolio Contact Form',
//text: 'Plaintext version of the message',
html: '<p>'+req.body.description+'</p>'
};
transporter.sendMail(message, function(error, info){
if(error){
res.json({error: error});
}else{
res.json({success: info.response});
};
});
})
You configure nodemailer transport with iCloud Service and you are trying to send a mail with a gmail adresse.
from: req.body.email, // meme#gmail.com
to: 'myemail#mac.com'
Which logically produces the error:
response:"550 5.7.0 From address is not one of your addresses."
You probably want to do the inverse.

Nodemailer sending mail again after 8 hours

I am using nodemailer module to send mail from the node server when users request for a new password using the following function:
function(email, password, callback) {
var smtpTransport = nodemailer.createTransport('SMTP', {
service: 'Gmail',
auth: {
user: 'something#gmail.com',
pass: 'my_password'
}
});
var mailOptions = {
from: 'My Team<something#gmail.com>',
to: email,
subject: 'new password',
text: 'login with email: ' + email + 'and password: ' + password,
html: '<p>login with email: ' + email + ' and password: ' + password +
'<br> Visit here to learn more ' + ' google</p>'
};
smtpTransport.sendMail(mailOptions, function(err, res) {
if(err) {
smtpTransport.close();
return callback(err);
} else {
smtpTransport.close();
return callback(null);
}
});
};
The email id I am using is a valid one. The user indeed gets a mail from this id containing a newly generated random password. However, he again gets a mail after exactly 8 hours containing yet another newly generated random password. I don't know how this function is called again after 8 hours on the server side.
I am using winston for logging all api calls and the data received in the request object. However the timestamp format is unfamiliar to me. How do I convert this
"timestamp":"2013-09-13T19:39:16.814Z" logged by winston to my local time? Also due to asynchronous nature of node.js the order in which api calls are logged is all interleaved and messed up. How do I log the api calls in the order they are called and served?

Resources