Configuring git send-email to use Gmail SMTP

Using msmtp to send your patches  – This method worked for me

NOTE: git send-email supports TLS/SSL now.

Mailing off a set of patches to a mailing list can be quite neatly done by git-send-email. One of the problems you may encounter there is figuring out which machine is going to send your mail. I tried, but that one requires tls and a password, and git-send-email could not handle that.

A neat little program, msmtp can help you there. Install and configure a .msmtprc file in your home directory, the likes of:

# Example for a user configuration file
# Set default values for all following accounts.
tls on
tls_trust_file /etc/pki/tls/certs/ca-bundle.crt
logfile ~/.msmtp.log
# My email service
account gmail
port 587
auth on
password my-secret
# Set a default account
account default : gmail

This takes gmail as an example. The password field is not required. msmtp will prompt you for your password if the field is omitted. The ca-bundle.crt is the file with CA certificates for Fedora Core 6, for other distros you might have to dig it up from somewhere else. On Ubuntu /etc/ssl/certs/ca-certificates.crt should be used, for example. Now, by giving the full path name to the msmtp program as smtp server to git-send-email, you can send the patches through gmail or some other smtp account with TLS and/or user authentication.

git-send-email --smtp-server /usr/local/bin/msmtp <file|directory>

An alternative to setting –smtp-server each time is to set the global sendemail.smtpserver value.

git-config --global sendemail.smtpserver /usr/local/bin/msmtp

Another option is to configure a local smtp server on your machine, using a well-known SMTP server as smarthost. Then, all applications using localhost as a mail server (e.g. /usr/bin/mail) will work.

Another method – I didn’t try it.
If you dont have the command git-send-email command then install it using apt-get install git-send-email

Then, add the correct configuration variables with the following:

$ git config --global sendemail.smtpserver
$ git config --global sendemail.smtpserverport 587
$ git config --global sendemail.smtpencryption tls
$ git config --global sendemail.smtpuser

Now it’s ready: the command git send-email patch-name will ask you for some info about the email sender (you can change the From: field) and recipient, your Gmail password and then it will send the email.

Optionally, it is possible to skip the password prompt by adding it to the configuration with:

$ git config --global sendemail.smtppass your_password

Thats it.

9 thoughts on “Configuring git send-email to use Gmail SMTP

  1. I like the helpful info you provide in your articles.
    I’ll bookmark your weblog and check again here frequently.
    I am quite sure I’ll learn lots of new stuff right here! Best of luck for the next!

  2. Have you ever considered adding more clips to your blog site posts to keep the subscribers more entertained? I mean I just read through the entire blog post of yours and it was quite fantastic but since I’m more of a visual learner,I found that to be more useful well let me know how it turns out! Respectfully, Marna.

  3. I always wanted to publish on my web page something like that. I usually don’t publish comments in blogs but your blog site compelled me to, tremendous effort.… My kind regards, Jacalyn.

  4. Hi, I have a specific question regarding SyntaxHighlighter. Could you send me a link to any tutorial, that explains how it can be used with standard wordpress accounts. I don’t see any way to upload plugins to the accounts. Sorry to bother you with such a mundane request.

    Thank you


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s