Send emails with git send-email over the Gmail API.
SendGmailAPI is a Go application that allows you to send emails using the Gmail
API. It's particularly useful for developers who want to use git send-email
with their Gmail account, bypassing the need for SMTP configuration.
Warning: Gmail automatically wraps emails to 72 characters, which breaks patches sent with
git send-email
.
- Go to the Google Cloud console and enable the Gmail API.
- In the Google Cloud console, go to OAuth consent screen.
- For User type, select Internal, then click Create.
- Complete the app registration form, then click Save and Continue.
- Skip adding scopes and click Save and Continue.
- Review your app registration summary. To make changes, click Edit. If the app registration looks OK, click Back to Dashboard.
- In the Google Cloud console, go to Credentials.
- Click Create Credentials > OAuth client ID.
- Click Application type > Web application.
- In the Name field, type a name for the credential like "sendgmailapi".
- Add http://localhost:8090 as an authorized redirect URI.
- Click Create. The OAuth client created screen appears, showing your new Client ID and Client secret.
- Download the JSON file with the credentials.
Note: This application now uses a local server to handle the OAuth2 flow, which is more secure and doesn't rely on external services.
- Create a directory for configuration:
mkdir -p ~/.config/sendgmail chmod 0700 ~/.config/sendgmail
- Move the downloaded JSON file to this directory:
mv ~/Downloads/client_secret*.json ~/.config/sendgmail/credentials.json chmod 0600 ~/.config/sendgmail/credentials.json
- Go back to APIs & Services > OAuth consent screen in the Google Cloud console.
- Add your Gmail address (e.g., USERNAME@gmail.com) as a test user.
Install sendgmailapi:
go install github.com/paralin/sendgmailapi@latest
Run the setup to get the token:
$(go env GOPATH)/bin/sendgmailapi -setup
This will open a browser window for you to authorize the application and generate the token.
Once set up, you can use SendGmailAPI to send emails. The application reads the email content from standard input.
Add to your .gitconfig at ~/.gitconfig:
git config --global sendemail.smtpServer $(go env GOPATH)/bin/sendgmailapi
Or to send a simple email:
echo "Subject: Test Email
To: recipient@example.com
This is a test email." | sendgmailapi
MIT