Reputation: 6552
I'm using the Nodemailer Node.js module to interface with sendmail. However, my emails go directly to the spam folder when reached by a Gmail account. Why are my emails being shit-canned? It must be something to do with the headers of the email, but I have no idea what it could be.
I'm not really familiar with emails and what spam filters look for, so could someone please provide me with some details on what to watch out for?
Thanks for reading. :)
Upvotes: 9
Views: 14512
Reputation: 5385
Here's a few reasons: So You'd Like to Send Some Email (Through Code) (2010)
There are also blacklists of ip addresses. Anything coming from these would just be ignored or regarded as spam. If your email is sent from a server which doesn't seem to be linked to the from address you'll have potential issues as well.
Detecting spam and trying not to be seen as spam are both non trivial things. That's why a lot of mailing lists are done through a specialist provider.
Upvotes: 1
Reputation: 41
I've faced with the same issue and was able to fix it by updating 'from' field to this format:
from: 'Sender Name <[email protected]>'
complete code:
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
requireTLS: true,
auth: {
user: '[email protected]',
pass: 'pass'
},
from: '[email protected]'
});
const mailOptions = {
from: 'Sender Name <[email protected]>'
to: '[email protected]',
subject: 'Subject',
text: 'Text'
};
return transporter.sendMail(mailOptions, (error, info) => {
...
});
Upvotes: 2
Reputation: 1204
data/mail.private - change to wherever your Open DKIM private key file is located.
var client = require('nodemailer').createTransport({
secure: false,
pool: true,
host: 'yourdomain.io',
port: app.nconf.get('mail:port'),
auth: {
user: app.nconf.get('mail:user'),
pass: app.nconf.get('mail:pass')
},
dkim: {
domainName: 'yourdomain.io',
keySelector: 'mail',
privateKey: require('fs').readFileSync('data/mail.private', {
encoding: 'utf8'
})
}
})
Upvotes: 0
Reputation: 444
In case if your IP is blacklisted, you will need to use third party email service like:
Check their documentation for integration with your application.
Upvotes: 0