Search code examples
javascriptnode.jsemailoauth-2.0google-workspace

nodemailer google workspace cant create new access token


I keep on getting this error my email system worked when I tested it with ethereal email but now I have tried to use it with Gsuite I am getting this error when my server tries to send from my google workspace email.

I have tried to use the google cloud platform tutorial https://developers.google.com/gmail/api/quickstart/nodejs and I am still getting this error I have also tried to set up a service account with the google cloud platform.

Could it be I did either of these processes wrong or something else, I am unsure of where to go.

Error: Can't create new access token for user
    at XOAuth2.generateToken (C:\Users\***\lib\xoauth2\index.js:184:33)
    at XOAuth2.getToken (C:\Users\***\lib\xoauth2\index.js:123:18)
    at SMTPConnection._handleXOauth2Token (C:\Users\***\lib\smtp-connection\index.js:1687:27)
    at SMTPConnection.login (C:\Users\***\lib\smtp-connection\index.js:530:22)
    at C:\Users\***\lib\smtp-transport\index.js:374:32
    at SMTPConnection.<anonymous> (C:\Users\***\lib\smtp-connection\index.js:209:17)
    at Object.onceWrapper (events.js:421:28)
    at SMTPConnection.emit (events.js:315:20)
    at SMTPConnection._actionEHLO (C:\Users\***\lib\smtp-connection\index.js:1303:14)
    at SMTPConnection._processResponse (C:\Users\***\lib\smtp-connection\index.js:932:20)
    at SMTPConnection._onData (C:\Users\***\lib\smtp-connection\index.js:739:14)
    at TLSSocket.SMTPConnection._onSocketData (C:\Users\***\lib\smtp-connection\index.js:189:44)
    at TLSSocket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:284:9)
    at TLSSocket.Readable.push (_stream_readable.js:223:10) {
  code: 'EAUTH',
  command: 'AUTH XOAUTH2'
}

Are there any suggestions on how I fix this problem and do you need any more information to help me fix this problem?


Solution

  • The problem was that I had to set up the oauth2 authentification in the https://developers.google.com/oauthplayground/ and allow mail.google access this in turn will get you a refresh token that you can use to generate your access token to solve the problem being caused in this response.

    I looked within the code of the library to see what exactly was going on and it helped put me in the right direction.