Skip to content

Instantly share code, notes, and snippets.

Last active March 28, 2023 12:11
  • Star 33 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jasonkarns/4354421 to your computer and use it in GitHub Desktop.
Git send-email using Gmail
  1. Configure git.
# ~/.config/git/config
  confirm = auto
  smtpServer =
  smtpServerPort = 587
  smtpEncryption = tls
  smtpUser = <gmail email address>
  1. Configure Authentication.

I believe the simplest setup is to create an application-specific password in Google dedicated to git.

Google Account -> Security -> Signing in to Google : App passwords

This password must be configured in git, but should be kept outside of your main gitconfig (which is likely versioned via a dotfile repo?). To do that, I use git's [include] directive.

# ~/.config/git/config
  path = config.local # (relative or absolute path to the other config file)
# ~/.config/git/config.local
  smtpPass = <app-specific-password>

Alternatively, check out which supports authenticating to GMail with OAuth2.

  1. Determine your revlist.

To send a single commit, just use the sha. To send a range of commits, you can use start_sha..end_sha. Most likely, you'll want to send the commits made to a branch that are missing in upstream. For that, you would use: upstream/branch_name..branch_name You can also use relative numbers to indicate the "previous X commits". e.g. git send-email -3

  1. Send email:
git send-email <revlist> --to <>
  1. If you receive an error like this:
Can't locate Net/SMTP/ in @INC (@INC contains: ...

You may need to upgrade/install the Net::SMTP::SSL or IO::Socket::SSL packages:

sudo -H cpan Net::SMTP::SSL
sudo -H cpan IO::Socket::SSL
  1. Advanced: configure multiple identites. You may configure multiple smtp servers and switch between them with identities.
[sendemail "gmail"]
  smtpUser =
  smtpServer =

[sendemail "outlook"]
  smtpUser =
  smtpServer =
  identity = outlook
Copy link

dayyan commented May 6, 2014

@jasonkarns I added another package that may need upgrading. (

Copy link

Note that the sendemail.from field in the git configuration isn't needed if and are defined. In fact, setting it to just an email address means that the mail will be sent without a name, which looks dumb.

Copy link

xloem commented Sep 23, 2018

Note: I couldn't make an app password, and kept getting junk ilke this despite repeatedly visiting the link and verifying my identity:

5.7.14 <
5.7.14 Sqh-d0mO0m15az13tmQgNJo8Clb9qT4TFHpiAyDRZmgrIcnO5iamPxcRUIr8wVOg6OPszB
5.7.14 VCCL1wb6mAT4aguBGLJ_-rKb5KptizHkWGrViPN6MDJMyuSc2Z7viiBHMVbpZKTkYqAmvz
5.7.14 ZH0w1ngbi_5o8w3oCE4XNIPNQKN0hJHwtO9c92uXVvj0SJFpYNX3SWFSte96tdAi75YUcR
5.7.14 rrTezfVs62SP10G7yhz597BWv4skqmpYlavZMwjNIaaTDkFM6MILIP0ubtRYGNI5dnAsuR
5.7.14 -07yiifJYq826D3PXorhlbEgGh_W469_dhuUJ_p70Krp0rLHvSIwHuZue4zcXCvbf2cDSS
5.7.14 sSfRO1UcmjuMyRVxUSU568c4mJp9GDgmCAnIWg3zHAMztpBrnMUAYwYaS_VvACiJ5e7y06
5.7.14 yWkveGA07XUX4UTWFhoHMKX80jhPwUHwpJngkz8Xl6AO9OHyUu2Qg3-QBvoU3FDfxiCRSg
5.7.14 eCRfw> Please log in via your web browser and then try again.
5.7.14  Learn more at
5.7.14 p5-v6sm17682914qkd.81 - gsmtp

The solution was:
A) posted a complaint on the google help forums at!forum/gmail ... I didn't get a reply, but after my post my account magically let me through some of the issues
B) log into my account from a local system, with no proxy (I was using Tor before)
C) enable 2-factor authentication
D) now, I could generate an app password and log in using git send-email (even from tor!) !

Copy link

I had to turn on "less secure apps" at to make this work.

Copy link

Thanks for the tip @johnlinp! I think it might've taken me awhile to find that 😄

Copy link

atykhyy commented Feb 14, 2020

For those who don't want to use their Gmail password for this or enable "less secure apps", I wrote a plug-in for git-send-email that uses OAuth 2 authorization. It requests only the minimum required permissions (send email on your behalf) and stores OAuth token data in Windows Credential Store, like Git Credential Manager does. Google has a plug-in which works in a similar fashion, but keeps credentials in a file, and uses less restricted tokens (all of Gmail vs just send email on your behalf). It works on Linux though.

Copy link

Copy link

ElectricRCAircraftGuy commented Jul 3, 2021

@johnlinp, it looks like you have to either use 2-factor authentication with an app-specific password, OR allow less secure app access. See here: I'd rather do the former, as it seems more-secure. I'm attempting to set this up now...


If you have multi-factor authentication set up on your Gmail account, you will need to generate an app-specific password for use with git send-email. Visit to create it.

If you do not have multi-factor authentication set up on your Gmail account, you will need to allow less secure app access. Visit to enable it.

Copy link

After a great deal of effort, I got it all working. See my full instructions on Stack Overflow now, here:

Copy link

hitmoon commented Jul 16, 2021

After a great deal of effort, I got it all working. See my full instructions on Stack Overflow now, here:

great work !

Copy link

bensuperpc commented Aug 21, 2021

On Manjaro (21.08), git config: ~/.gitconfig
And need these packages: perl-mime-tools perl-authen-sasl

Copy link

ghost commented Mar 7, 2022

I had to turn on "less secure apps" at to make this work.

This will no longer work after May 30, as of Google said to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment