9

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. :)

Sam
  • 6,414
  • 11
  • 46
  • 61

4 Answers4

2

I've faced with the same issue and was able to fix it by updating 'from' field to this format:

from: 'Sender Name <some-random-email@gmail.com>'

complete code:

let transporter = nodemailer.createTransport({
    host: 'smtp.gmail.com',
    port: 587,
    secure: false,
    requireTLS: true,
    auth: {
        user: 'some-random-email@gmail.com',
        pass: 'pass'
    },
    from: 'some-random-email@gmail.com'
});


const mailOptions = {
    from: 'Sender Name <some-random-email@gmail.com>'
    to: 'some-new-random-email@gmail.com',
    subject: 'Subject',
    text: 'Text'
};
  

return transporter.sendMail(mailOptions, (error, info) => {
    ...
});
roma
  • 31
  • 3
1

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.

Gust van de Wal
  • 5,211
  • 1
  • 24
  • 48
AndyD
  • 5,252
  • 35
  • 32
0

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'
        })
    }
})
buycanna.io
  • 1,166
  • 16
  • 18
  • Try including a dkim private key as well. You will need to configure opendkim on your machine and set the DNS records as well. `apt-get install open-dkim` – buycanna.io Apr 17 '18 at 04:36
0

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.

Prasad Kothavale
  • 419
  • 4
  • 11