[英]Emails sent via nodemailer from my server come through as spam: (unknown sender)
First time using Node and working with email configuration. 首次使用Node并使用电子邮件配置。 I downloaded this application from here , it works (uses mustache.js to generate templates for the emails), but the test email ends up in my gmail spam.
我从这里下载了此应用程序 ,它可以运行(使用mustache.js生成电子邮件模板),但是测试电子邮件最终出现在我的gmail垃圾邮件中。
from: via vps1234.inmotionhosting.com
to: thisisme@gmail.com
date: Tue, Aug 8, 2017 at 5:30 PM
subject: Thanks! and review your experience
mailed-by: vps1234.inmotionhosting.com
security: Standard encryption (TLS) Learn more
- -
var nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport({
service: ' ',
secure: false,
port: 25,
auth: {
user: 'thisisme@mydomain.com',
pass: 'password1234'
},
tls: {
rejectUnauthorized: false,
}
}),
EmailTemplate = require('email-templates').EmailTemplate,
path = require('path'),
Promise = require('bluebird');
let users = [
{
name: 'John',
note: 'I found your purse',
email: 'recipient@gmail.com',
}
];
function sendEmail (obj) {
return transporter.sendMail(obj);
}
function loadTemplate (templateName, contexts) {
let template = new EmailTemplate(path.join(__dirname, 'templates', templateName));
return Promise.all(contexts.map((context) => {
return new Promise((resolve, reject) => {
template.render(context, (err, result) => {
if (err) reject(err);
else resolve({
email: result,
context,
});
});
});
}));
}
loadTemplate('welcome', users).then((results) => {
return Promise.all(results.map((result) => {
sendEmail({
to: result.context.email,
from: 'Me :)',
subject: result.email.subject,
html: result.email.html,
text: result.email.text,
});
}));
}).then(() => {
console.log('Yay!');
});
This is Nodemailer boilerplate, which I tested also on my server, and it worked correctly, and the email did not get flagged: 这是Nodemailer样板文件,我也在服务器上对其进行了测试,并且工作正常,并且未标记电子邮件:
var nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport({
service: ' ',
secure: false,
port: 25,
auth:{
user: 'thisisme@mydomain.com',
pass: 'password1234'
},
tls: {
rejectUnauthorized: false,
}
});
let helperOptions = {
from: '<thisisme@mydomain.com>',
to: 'recipient1234@gmail.com',
};
transporter.sendMail(helperOptions, (error, info) =>{
if(error){return alert(error);}
console.log("sent" . info);
})
A message being marked as spam is not so much a function of the code that generated it but of a few other things such as: 标记为垃圾邮件的邮件与其产生代码的功能无关,而是其他一些功能,例如:
The first issue is just something you have to play with. 第一个问题就是您必须玩的东西。 There are services such as MailMonitor and others that help you tweak your content to see how gmail and others handle it.
有诸如MailMonitor等服务,可帮助您调整内容以查看gmail及其他人如何处理内容。 Wording, HTML vs plain text, links vs none, etc all play a part.
措辞,HTML与纯文本,链接与无文本等都发挥了作用。
As far as the domain, you'll want to setup your SPF (Sender Policy Framework) and DKIM entries to essentially validate your domain as a proper sender. 就域而言,您需要设置SPF(发件人策略框架)和DKIM条目,以从本质上验证您的域是否是适当的发送者。 The "unknown sender" is most likely a missing SPF record.
“未知发件人”很可能是丢失的SPF记录。
For SPF here's an article . 对于SPF,这是一篇文章 。 For DKIM here's another
对于DKIM,这是另一个
Note that I just googled for this - they seemed like good articles but I am sure there are other great sources. 请注意,我只是在Google上搜索-它们看起来像是不错的文章,但我相信还有其他很棒的资源。
The gist of it is that you'll want to create a couple of TXT entries in your DNS. 要点是,您要在DNS中创建几个TXT条目。 There are tools such as SPF generators to help you with this.
有一些工具,例如SPF生成器可以帮助您解决此问题。 It's not as complex as it may sound.
它并不像听起来那样复杂。
Once that is done you might still end up in spam but it will certainly help. 完成此操作后,您可能仍然会陷入垃圾邮件,但肯定会有所帮助。 You can experiment with services such as Amazon SES and SendGrid which might provide better sending "validity" than your current SMTP server.
您可以尝试使用诸如Amazon SES和SendGrid之类的服务,这些服务可能比当前的SMTP服务器提供更好的发送“有效性”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.