email Git Linux: /etc/hosts committer config Git mta push
by bseanvt
leave a comment
Have Git Email Committers After Pushes
You need a Mail Transfer Agent MTA on the server. The easiest way is to install Sendmail, which Git uses by default.
apt-get install sendmail
Remember that /etc/hosts file needs the ip address to map to the domain name your sending mail from
# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain 207.136.202.87 wwwexample.com
Sendmail has a tendency to hang when sending mail otherwise. To test sendmail
sendmail email@example.com this is a test how are you today world? .
The period on a line by itself denotes end of message and will terminate the prompt and deliver the message.
Now you need to configure Git to send email after it receives a “push” from a committer. You can add email addresses, or you can set up a mailing list to email all members. Either way, you accomplish this with the following command, just remember to cd into the git repository.
git config --add hooks.mailinglist "mailinglist@example.com"
Next you need to activate the post-receive hook, located in the hooks directory of your repository.
cp post-receive.sample post-receive
And uncomment the last line, which uses sendmail to deliver the commit message
# uncomment the last line but keep the period "." . /usr/share/doc/git-core/contrib/hooks/post-receive-email
All done. Now just make some changes to your source code, add and commit them and you should receive an email with all the details!
Using sendmail to send mail on ubuntu box
I normally install postfix for my MTA. However, I’ve never really used sendmail so I’d decide to give it a whirl for a new application I’m working on. I don’t use it for anything but handling the mail that the application needs to send out, like new user welcome emails, password resets, etc.
apt-get install sendmail
Sendmail, unlike postfix, won’t work out of the box. Postfix will prompt you for the necessary config setup when running the install. Sendmail won’t, and therefore it’s not ‘out of the box’. You’ll have to make some modifications on your own. Nothing major but this is what I’ve found in order to get it to work, reliably and quickly. The first thing I did was add the fully qualified domain name to my /etc/hosts file
#vim /etc/hosts 127.0.0.1 www.mydomain.com
After this I added the fully qualified domain name to my apache default configuration file
#/etc/apache2/sites-available/default ServerName www.mydomain.com #vhost info etc...
Reload and restart…
/etc/init.d/apache2 force-reload /etc/init.d/sendmail restart
You can test sendmail like so
sendmail email@example.com hello from me .
This should deliver a message to you (the “.” on a new line, followed by a new line, closes the message).


