git-credential-email

This repo contains the following helpers:

They can be used with git send-email, especially when Outlook no longer supports app passwords.

How does this work?

It is a simple python script, based on https://github.com/google/gmail-oauth2-tools/blob/master/python/oauth2.py and https://github.com/opulentfox-29/protonmail-api-client. It does the following:

Installation

All platforms

Linux

Ubuntu/Debian

Run the following to add the apt repo and install the helpers:

curl -L "https://github.com/AdityaGarg8/git-credential-email/releases/download/debian/KEY.gpg" \
	| gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/git-credential-email.gpg >/dev/null \
	&& echo "deb [signed-by=/etc/apt/trusted.gpg.d/git-credential-email.gpg] \
	https://github.com/AdityaGarg8/git-credential-email/releases/download/debian ./" \
	| sudo tee -a /etc/apt/sources.list.d/git-credential-email.list \
	&& sudo apt-get update \
	&& sudo apt-get install -y git-credential-gmail git-credential-outlook git-credential-yahoo git-credential-aol git-msgraph git-protonmail

Fedora

Run the following to add the copr repo and install the helpers:

sudo dnf copr enable -y adityagarg8/git-credential-email
sudo dnf install -y git-credential-gmail git-credential-outlook git-credential-yahoo git-credential-aol git-msgraph git-protonmail

macOS

Install Homebrew. Then run the following to add the brew tap and install the helpers:

brew tap adityagarg8/git-credential-email
brew install git-credential-gmail git-credential-outlook git-credential-yahoo git-credential-aol git-msgraph git-protonmail

Windows

Precompiled binaries for Windows are available. You can download the zip containing them from here. Extract all the contents of the zip in your path. %ProgramFiles%\Git\mingw64\libexec\git-core is also a part of %PATH% when git is installed on Windows. As an example, to install git-credential-gmail on Windows over there, open Command Prompt as administrator and run the following:

curl -L -o %temp%\cred.zip https://github.com/AdityaGarg8/git-credential-email/releases/latest/download/git-credential-gmail_win64.zip
tar -xf %temp%\cred.zip -C "%ProgramFiles%\Git\mingw64\libexec\git-core"

Setting up OAuth 2.0 client credentials

You can skip this section if you are using ProtonMail

In order to use OAuth2.0, you need to provide an OAuth 2.0 client_id and a client_secret (secret not needed in Outlook) to allow the helper to authenticate with email servers on your behalf.

If not configured, it will use Thunderbird’s client_id and client_secret by default.

The helpers include the client credentials of the following popular email clients:

In order to set the client credentials of your choice, run (taking git credential-gmail as an example):

git credential-gmail --set-client

Here you can either choose from the pre-configured client credentials, or choose to use your own registered client. Instructions for registering your own client are given below:

In case you want to delete the client credentials you stored and go back to the default behaviour, run:

git credential-gmail --delete-client

Authenticating with your email provider

Now we need to authenticate with our email provider to get the necessary tokens to authenticate using OAuth2.0.

Note: Except for git-msgraph and git-protonmail, make sure you have atleast version 2.1800 of perl’s Authen::SASL library in order to be able to use OAuth2.0. You can run cpan install Authen::SASL to install the latest version of this library. git-msgraph and git-protonmail do not require this library.

Gmail

Outlook

Using the SMTP server

Microsoft Outlook accounts can send emails using two methods. First is their SMTP server, which is similar to what most email providers use. Second is Microsoft Graph API. These instructions are in case you want to use the SMTP server.

Note: It is recommended to use atleast git 2.50 for threads to properly work with Outlook’s SMTP server. If you are using an older version of git, then its better to use Microsoft Graph API using git-msgraph for threads to work properly.

Using Microsoft Graph API

Microsoft Graph API can be used instead of Outlook’s SMTP server to send emails. Microsoft Graph API tends to be faster than SMTP. If you want to use Microsoft Graph API to send emails, follow these instructions.

Yahoo

AOL

ProtonMail

Solving CAPTCHA while authenticating in ProtonMail

There is a high chance that you will be asked to solve a CAPTCHA when you try to authenticate for ProtonMail. The on-screen instructions should be followed while solving the CAPTCHA.

For an easier CAPTCHA solving experience, you can install either PyQt6-WebEngine or OpenCV.

PyQt6-WebEngine will open a dedicated broswer window for solving CAPTCHA for you to solve and send the solved CAPTCHA to the credential helper. It occupies around 100-200MBs depending on your OS.

OpenCV is more advanced and can automatically solve the CAPTCHA 99% times, without you needing to solve it at all! But it also occupies around 600MBs. An alternate is opencv-python-headless available using pip that is lighter, and is the best option for headless systems. It is not available if you are using apt/dnf/brew to install the helper. If you are using a Windows binary, opencv-python-headless is bundled by default.

I would recommend installing PyQt6-WebEngine if you are on a system with GUI and OpenCV for headless systems.

You can install them by running (modify the commands accordingly if you want to install only one of them):

Usage

Gmail

  [credential "smtp://smtp.gmail.com:587"]
        helper = 
        helper = gmail
  [sendemail]
        smtpEncryption = tls
        smtpServer = smtp.gmail.com
        smtpUser = someone@gmail.com # Replace this with your email address
        smtpServerPort = 587
        smtpAuth = OAUTHBEARER
        from = Your Name <someone@gmail.com> # Replace this with your name and email address

Outlook

Using the SMTP server

  [credential "smtp://smtp.office365.com:587"]
        helper = 
        helper = outlook
  [sendemail]
        smtpEncryption = tls
        smtpServer = smtp.office365.com
        smtpUser = someone@outlook.com # Replace this with your email address
        smtpServerPort = 587
        smtpAuth = XOAUTH2
        from = Your Name <someone@outlook.com> # Replace this with your name and email address

Using Microsoft Graph API

  [sendemail]
        sendmailCmd = git-msgraph
        from = someone@outlook.com # Replace this with your email address

Yahoo

  [credential "smtp://smtp.mail.yahoo.com:587"]
        helper = 
        helper = yahoo
  [sendemail]
        smtpEncryption = tls
        smtpServer = smtp.mail.yahoo.com
        smtpUser = someone@yahoo.com # Replace this with your email address
        smtpServerPort = 587
        smtpAuth = OAUTHBEARER
        from = Your Name <someone@yahoo.com> # Replace this with your name and email address

AOL

  [credential "smtp://smtp.aol.com:587"]
        helper = 
        helper = aol
  [sendemail]
        smtpEncryption = tls
        smtpServer = smtp.aol.com
        smtpUser = someone@aol.com # Replace this with your email address
        smtpServerPort = 587
        smtpAuth = OAUTHBEARER
        from = Your Name <someone@aol.com> # Replace this with your name and email address

ProtonMail

  [sendemail]
        sendmailCmd = git-protonmail
        from = someone@proton.me # Replace this with your email address. If you have multiple addresses (seen in paid accounts), use the address you want to send from.

Deleting the stored authentication details

In case you want to delete the refresh token, that was stored by the helper, as mentioned here, simply run (taking git credential-gmail as an example):

git credential-gmail --delete-token

For ProtonMail, you need to delete both the session file and the key that encrypted it. This command will help you for that:

git protonmail --delete-session

Troubleshooting

In case authentication fails:

  1. Try force refreshing the access token by running (taking git credential-gmail as an example):

    git credential-gmail --force-refresh-token
    
  2. If --force-refresh-token does not work, try authenticating again.

References: