sendgmail is a tool that uses Gmail in order to mimic sendmail for git send-email.
-
Go to the Google Cloud console.
- Create a new project. You probably want to name it something like sendgmail in IAM & Admin > Settings and also in APIs & Services > OAuth consent screen.
-
Go to the Go quickstart page of the Gmail API documentation.
-
Click the Enable the API button. It will open another page in your browser. Follow the steps on that page to enable the Gmail API for the project that you created.
-
Follow the steps in the Authorize credentials for a desktop application section. However, set the application type to Web application (i.e. instead of Desktop app) and then add
https://google.github.io/gmail-oauth2-tools/html/oauth2.dance.htmlas an authorised redirect URI. This is necessary for seeing the authorisation code on a page in your browser. -
When you download the credentials as JSON, create the
${XDG_CONFIG_HOME:-${HOME}/.config}/sendgmaildirectory with file mode0700and then save the file to that directory asconfig.jsonwith file mode0600.For historical reasons, when the file named
config.jsondoes not exist under your config directory, sendgmail will try looking for a file named.sendgmail.jsonin your home directory.
-
-
Go back to APIs & Services > OAuth consent screen in the Google Cloud console.
-
Add
[email protected]as a test user. This is necessary for using the project that you created. -
Add
https://mail.google.com/as a scope. This is necessary for using Gmail via SMTP.
-
Run the following command to build and install sendgmail to
GOPATH/bin/sendgmail:
go install github.com/google/gmail-oauth2-tools/go/sendgmail@latestRun the following command to perform the OAuth2 dance:
GOPATH/bin/sendgmail [email protected] -setupAdd the following section to .gitconfig in your home directory:
[sendemail]
smtpServer = GOPATH/bin/sendgmail
smtpServerOption = [email protected]