Search code examples
oauth-2.0smtpgmailcommand-line-interface

How to authenticate smtp gmail using XOAUTH2 from command line?


i have setup desktop client in oauth consent screen for a test api to access gmail api to send email?

When trying to authenticate to gmail using oauth2 from command line i get the below error?

AUTH LOGIN XOAUTH2
334 UGFzc3dvcmQ6
<base64 encoded string>
535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials u12-20020a170902b28c00b0019c2b1c4db1sm2373754plr.239 - gsmtp

How to send email using oauth2 using commandline from smtp gmail account? Please help me?


Solution

  • Encoded access token has problem with control characters. I should be typing <ctrl+A> but i was typing ^A when preparing XOAUTH2 token. It's documented here from google

    developers.google.com/gmail/imap/xoauth2-protocol 
    
    "Use the base64 encoding mechanism defined in RFC 4648. ^A represents a Control+A (\001)."