问题
I am sending email through nodemailer it goes into inbox of gmail if i run from local server but goes into spam of gmail if i run script from microsoft azure server. following is my script
var nodemailer = require('nodemailer');
var EmailTemplates = require('swig-email-templates');
var smtpConfig = {
service: 'smtp.office365.com',
host: 'smtp.office365.com',
port: 587,
starttls: {
enable: true
},
secureConnection: true,
auth: {
user: 'xxxxx@yyyy.com',
pass: 'zzzzzz'
}
}
var templates = new EmailTemplates();
var transporter = nodemailer.createTransport(smtpConfig);
var context = {
username:'Rajesh',
email:'xxxxx@gmail.com',
link : 'www.google.co.in'
};
templates.render('activate_email.html', context, function(err, html,text, subject) {
transporter.sendMail({
from: '"Product Name👥" <no-reply@xxxxx.com>', // sender address
to: 'xxxx@gmail.com',
subject: 'Account activation',
html: html,
text:text
});
});
回答1:
The truth is there is no simple one line solutions for your problem :) There are numerous reasons why this can happen, and here are some of them:
Your host is marked as a spam - this happens if you have not verified your e-mail or you are sending too much e-mails from the same host. Shared hosting is commonly marked as such, and therefore mail server will regularly mark them as a spam
Your
from
field is different than the one you're allowed to use - as I see you're using smtp, there are strict rules for the mail you can send. Of course you can always send e-mail frommark@facebook.com
, but since your SMTP's host is not facebook.com, your e-mail will pretty sure marked as spamYou can sign your e-mail in many various mails, assuring the servers that this e-mail is send from you and it has proper signature. Check online for the ways to do so.
While developing you have sent numerous alike e-mails - sending the very same "test" e-mail is a common reason for your e-mails to get blacklisted
There are emojis in your subject - that is not a 100% reason, but servers are often marking such e-mails as spams, especially in other fields (like
from
)
Unfortunately as I said there is no one real reason, there could be many of them. I hope this helps at least a little :)
回答2:
Please get rid of the 👥 and try sending it again. I read in a article once that email clients don't like those icons because a lot of spammers are using them.
Try sending it to multiple gmail accounts. Other than that there's nothing wrong with the code. If you're on a shared hosting or local host it could also go into the junk folder. In that case you would have to look into sending the emails from a different IP, preferred in the same country as where you will send the emails to.
But first try to remove that icon!
PS. I would make this answer as a comment but I can't due to low rep.
来源:https://stackoverflow.com/questions/40608635/email-send-through-nodemailer-goes-into-spam-for-gmail