Preventing Spam; Using Nodemailer; Using Sendmail
Asked Answered
S

4

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

Shantelleshantha answered 3/7, 2013 at 19:34 Comment(0)
D
2

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) => {
    ...
});
Dropsical answered 2/12, 2021 at 22:31 Comment(0)
P
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.

Probabilism answered 3/7, 2013 at 23:42 Comment(0)
L
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'
        })
    }
})
Lengel answered 17/4, 2018 at 4:35 Comment(1)
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-dkimLengel
C
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.

Channa answered 17/4, 2018 at 5:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.