Friday, 2 June 2017

nodemailer 4 breaks my authentication (from node mailer 2.7)

In nodemailer 2.7 I could use gmail as an outgoing mail server with the following code (I've replaced all the security stuff with gibberish just to post this, but that is not the problem):

import * as nodemailer from 'nodemailer';
var xoauth2 = require('xoauth2');

let transporter = nodemailer.createTransport(
    {
        service:'Gmail',
        auth:{
            xoauth2: xoauth2.createXOAuth2Generator( {
                user:'user@place.com',
                clientId:'00000000',
                clientSecret:'00000000',
                refreshToken:'1/00000000',
                accessToken: 'ya29.00000000'
            })
        }
    });
transporter.verify( (error, success) => {
    debug("Mail connection was successful? "+success);
    if (error){
        debug("Mail connection error: "+JSON.stringify(error));
    }
});

So that worked very reliably for a long time.

I upgraded to nodemailer 4, and it says that the parameter is not of the correct type. I referred to the documentation and it seemed like I could change my code to the following:

let transporter = nodemailer.createTransport(
    {
        service:'Gmail',
        auth:{
            type: 'OAuth2',
            user:'user@place.com',
            clientId:'0000000',
            clientSecret:'0000000',
            refreshToken:'1/00000000',
            accessToken: 'ya29.0000000000'            
        }
    });

transporter.verify( (error, success) => {
    debug("Mail connection was successful? "+success);
    if (error){
        debug("Mail connection error: "+JSON.stringify(error));
    }
});

...but this gives the error returned:

{"code":"EAUTH","response":"535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8  https://support.google.com/mail/?p=BadCredentials e76sm42171754pfb.92 - gsmtp","responseCode":535,"command":"AUTH PLAIN"}

How do I update my working code (the first snippet) from nodemailer 2.7 to work in version 4?



via WillyC

No comments:

Post a Comment