node.jsgmailnodemaileremail-spam

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: 'xxxxx@yyyy.com',
            pass: 'zzzzzz'
        }
    }

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

var context = {
  username:'Rajesh',
  email:'xxxxx@gmail.com',
  link : 'www.google.co.in'
};

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

  transporter.sendMail({
    from: '"Product Name👥" <no-reply@xxxxx.com>', // sender address
    to: 'xxxx@gmail.com',
      subject: 'Account activation',
      html: html,
      text:text    
  });    
});

Solution

  • 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:

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