Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing Spam; Using Nodemailer; Using Sendmail

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

like image 823
Sam Avatar asked Jul 03 '13 19:07

Sam


2 Answers

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) => {
    ...
});
like image 128
roma Avatar answered Sep 21 '22 17:09

roma


Here's a few reasons: http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html

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.

like image 44
AndyD Avatar answered Sep 18 '22 17:09

AndyD