Monthly Archives: July 2013

设置git使用msmtp发送patch

如果仅仅让git-send-email使用msmtp来发送patch,配置起来还是很简单的。首先配置msmtp。

# cat ~/.msmtprc
# Set default values for all following accounts.
defaults
logfile ~/.msmtp.log

# Gmail account
account gmail
host smtp.gmail.com
port 587
tls on
tls_trust_file /etc/pki/tls/certs/ca-bundle.crt
from username@gmail.com
auth on
user username@gmail.com
password password

# Company account
account company
host smtp.example.com
from user@example.com
user user@example.com
#password somepasswd

# Set a default account
account default : company

我这里设置了两个帐号,一个是gmail的一个是公司的邮箱,并且设置公司邮箱为默认帐号。

那么用git-send-email的命令就是

git send-email --to receiver@host.com --smtp-server /usr/bin/msmtp your.patch

也可以把msmtp写进git的配置

# cat ~/.gitconfig
......
[sendemail]
        smtpserver = /usr/bin/msmtp
# git send-email --to receiver@example.com your.patch

但是当你想在针对某个git repo发出去的patch使用gmail帐号发,上边的方法就不行了,需要给msmtp增加”-a gmail”参数,来告诉msmtp使用gmail这个帐号。

# cat .git/config
......
[sendemail]
        smtpserver = /usr/bin/msmtp
        smtpserveroption = -a
        smtpserveroption = gmail

需要注意的是每一个参数都要占用一个 smtpserveroption 行,git send-email –help然后搜索smtpserveroption就可以看到说明

The --smtp-server-option option must be repeated for each option you want to pass 
to the server. Likewise, different lines in the configuration files must be used
for each option.