8

I googled this but could not find an answer for my problem. here is my code

var xoauth2 = require('xoauth2');

var transporter = nodemailer.createTransport({
  service: "Gmail",
  auth: {
    xoauth2: xoauth2.createXOAuth2Generator({
      user: "dude@gmail.com", 
      clientId: "-",
      clientSecret: "-",
      refreshToken: "-"
       })
  }
});

app.post('/send', function (req, res) {
  var mailOptions = {
      from: 'dude',
      to: 'derp@gmail.com',
      subject: 'Email Example',
      text: 'username: ' + req.body.firstname,
      attachments:[
        {
          filename: req.files.myfile.name,
          content: new Buffer(req.files.myfile.data,'utf-8')
        }
      ]
  };

  transporter.sendMail(mailOptions, function(error, info){
    if(error){
      console.log(error);
      res.send(error);
    } else {
      console.log('Message sent!!');
      res.send('sent');
    }
  });
});

i used to have this problem back when i did not use oauth2, now that im using it i thought it would go away but it didnt. what am I doing wrong here?

dg2903
  • 613
  • 6
  • 12

2 Answers2

44

Ok so it was because of the Anti-Virus software. i swear things like this make me feel like quitting.

dg2903
  • 613
  • 6
  • 12
  • 6
    Same here. To be specific, in my case it was Avasts mail shield. Thanks for doing the right thing and posting the answer even though you solved it yourself! – SystemicPlural Oct 18 '17 at 09:12
  • 1
    Thanks. That's I love Linux. My colleague was working on window and that's how we come here. – Adiii Nov 20 '18 at 07:53
  • 1
    I laughed so hard at this. You just saved me a great deal of pain. Been at it for close to six hours until I finally decided to mute the antivirus. Funny thing it was working before. Maybe the antivirus just got suspicious and disabled it. Thank you so much for this. – iamcastelli May 08 '20 at 21:50
  • you just saved me days of headaches and crying – Jriffs Jul 31 '23 at 18:43
13

Same was with me. My antivirus is AVG. Instead of turning the antivirus off in AVG you can go to Settings>Components>Email Shield>Customize>SSL Scanning and uncheck "Scan SSL connections".

In Avast Go Settings/Protection/Core Shields/Configure shield settings/Mail Shield and uncheck "Scan outbound emails (SMTP)"

Namig Hajiyev
  • 1,117
  • 15
  • 16