Gmail

From wikinotes

Documentation

gmail oauth2 api docs https://developers.google.com/identity/protocols/oauth2/native-app
gmail oauth2 official client https://github.com/googleapis/google-api-python-client
gmail oauth2 challenge script https://github.com/google/gmail-oauth2-tools/blob/master/python/oauth2.py

Authentication

Login

NOTE:

no longer available

# configure gmail to accept login as authentication method

- visit: https://myaccount.google.com/security
  - Less Secure Apps (header):
    - Turn on Access
      - [x] Allow less secure apps

OAUTH2

See https://developers.google.com/identity/protocols/oauth2/native-app#step1-code-verifier

Create Project, and Access Scopes


- visit: https://console.developers.google.com/

  # 1) create project
  - ‘Select a project’ (drop down, header)
    - New Project
      - name: oauth2 mail
      - CREATE

  # 2) Enable Gmail API
  - APIs & Services:
    - [+] ENABLE APIS AND SERVICES (top/middle of page)
    - Search: Gmail API
      - Enable

  # 3) Assign token/access scopes
  - OAuth consent screen: (sidebar)
    - 1. OAuth consent screen ...
      - App name:  <your app>
      - User support email:  <your email>
      - developer email address: <your email>
      - Save and Continue
    
    - 2. Scopes:
      - Add Or Remove Scopes:
        - https://mail.google.com/  # read, compose, send and permanently delete email from gmail
      - Save and Continue
    
    - 3. Test Users
      - Add Users:
        - <your email>
        - Add
        - Add (press 2nd time to confirm)
      - Save and Continue
    
    - 4. Summary
      - Back to dashboard

Request Token


# download script: https://github.com/google/gmail-oauth2-tools/blob/master/python/oauth2.py

python2 oauth2.py \
  --user=<your_email> \
  --client_id=<your_oauth2_client_id> \
  --client_secret=<your_oauth2_secret> \
  --generate_oauth2_token

# visit URL
#  Advanced:
#    Go to <your app> (unsafe)
#
# Allow
#
# Copy verification code

# Paste verification code in CLI prompt

# You'll receive 2x tokens (refresh/access).
# You probably want the REFRESH TOKEN


App Passwords

Even if your email is behind a MFA, you may still be able to create an app-password to access it.
Logins are then treated like LOGIN auth.

- https://myaccount.google.com/security
  - Signing In to Google:
    - App Passwords:
      # create your password

Configuration

disable spam filtering

NOTE:

I haven't tested this yet.

https://webapps.stackexchange.com/questions/22802/how-can-i-remove-spam-filtering-in-gmail