Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email send through nodemailer goes into spam for gmail

I am sending email through nodemailer it goes into inbox of gmail if i run from local server but goes into spam of gmail if i run script from microsoft azure server. following is my script

var nodemailer = require('nodemailer');
var EmailTemplates = require('swig-email-templates');
var smtpConfig =  {
        service: 'smtp.office365.com',
        host: 'smtp.office365.com',
        port: 587,
        starttls: {
            enable: true
        },
        secureConnection: true,
        auth: {
            user: '[email protected]',
            pass: 'zzzzzz'
        }
    }

var templates = new EmailTemplates();  
var transporter = nodemailer.createTransport(smtpConfig);   

var context = {
  username:'Rajesh',
  email:'[email protected]',
  link : 'www.google.co.in'
};

templates.render('activate_email.html', context, function(err, html,text, subject) {    

  transporter.sendMail({
    from: '"Product Name👥" <[email protected]>', // sender address
    to: '[email protected]',
      subject: 'Account activation',
      html: html,
      text:text    
  });    
});
like image 331
Rajesh Nasit Avatar asked Nov 15 '16 11:11

Rajesh Nasit


People also ask

Why are my outgoing emails going to spam Gmail?

This practice is called spoofing, and it can cause Gmail to mark the messages as spam. To help prevent valid messages from being marked as spam: Messages that have a From address in the recipient's Contacts list are less likely to be marked as spam. Occasionally, valid messages might be marked as spam.

How do you fix a email that goes to spam in Gmail?

Add trusted senders to the spam bypass filter Create an allowlist by adding domains or addresses to a list of senders that bypass Gmail spam filters. Messages from domains or email addresses in your spam filter are more likely to be delivered to users' inboxes.

Does Nodemailer work with Gmail?

Once less secure apps is enabled now nodemailer can use your gmail for sending the emails.


3 Answers

The truth is there is no simple one line solutions for your problem :) There are numerous reasons why this can happen, and here are some of them:

  • Your host is marked as a spam - this happens if you have not verified your e-mail or you are sending too much e-mails from the same host. Shared hosting is commonly marked as such, and therefore mail server will regularly mark them as a spam

  • Your from field is different than the one you're allowed to use - as I see you're using smtp, there are strict rules for the mail you can send. Of course you can always send e-mail from [email protected], but since your SMTP's host is not facebook.com, your e-mail will pretty sure marked as spam

  • You can sign your e-mail in many various mails, assuring the servers that this e-mail is send from you and it has proper signature. Check online for the ways to do so.

  • While developing you have sent numerous alike e-mails - sending the very same "test" e-mail is a common reason for your e-mails to get blacklisted

  • There are emojis in your subject - that is not a 100% reason, but servers are often marking such e-mails as spams, especially in other fields (like from)

Unfortunately as I said there is no one real reason, there could be many of them. I hope this helps at least a little :)

like image 90
Andrey Popov Avatar answered Oct 12 '22 22:10

Andrey Popov


Please get rid of the 👥 and try sending it again. I read in a article once that email clients don't like those icons because a lot of spammers are using them.

Try sending it to multiple gmail accounts. Other than that there's nothing wrong with the code. If you're on a shared hosting or local host it could also go into the junk folder. In that case you would have to look into sending the emails from a different IP, preferred in the same country as where you will send the emails to.

But first try to remove that icon!

PS. I would make this answer as a comment but I can't due to low rep.

like image 45
Kaasstengel Avatar answered Oct 12 '22 23:10

Kaasstengel


in my case i needed to specify the form, the from need to be = to user mail

auth: {
  user: "[email protected]",
  pass: "password",
      }, 
from: [email protected], 
like image 7
asli Avatar answered Oct 12 '22 23:10

asli