SVN commit to Google Apps email notification
April 8th, 2009I had a sensitive SVN repository, where I want to get notification of each commit as an email to my Google Apps email address. There are a few post commit hooks available for SVN but they did not satisfy my requirements as they use sendmail to send email and I want to use secure SMTP provided by Google apps. So, I changed the example python script a little bit. Here are a few steps to achieve this functionality:
- Get the example mailer script from:
http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/mailer/
and save to some place like: /usr/share/subversion/hook-scripts/mailer/ - Rename the “mailer.conf.example” to “mailer.conf”
- Edit the mailer.conf
- Uncomment the line smtp_hostname = localhost
and change it to smtp_hostname = smtp.gmail.com - Uncomment smtp_username = example and change example with YOURNAME@YOURDOMAIN.com
- Uncomment smtp_password = example and change example with your real password.
- Add following two lines:
smtp_port = 587
smtp_use_tls = 1 - Set the from_addr, to_addr and reply_to variables.
- Add the map settings if you want (optional)
- Uncomment the line smtp_hostname = localhost
- Edit the file mailer.py
Modify the finish method of SMTPOutput class and replace it with following code:server = smtplib.SMTP(self.cfg.general.smtp_hostname, self.cfg.general.smtp_port) if self.cfg.is_set('general.smtp_username'): server.ehlo() if self.cfg.general.smtp_use_tls: server.starttls() server.ehlo() server.login(self.cfg.general.smtp_username, self.cfg.general.smtp_password) server.sendmail(self.from_addr, self.to_addrs, self.buffer.getvalue()) server.rset() server.quit() - Now goto “hooks” directory in your repository and make a new file as “post-commit”
- Chmod “post-commit” to 755
- Edit the “post-commit” and enter following contents:
#!/bin/sh REPOS="$1" REV="$2" /usr/share/subversion/hook-scripts/mailer/mailer.py commit "$REPOS" \ "$REV" /usr/share/subversion/hook-scripts/mailer/mailer.conf
This cup of tea was served by: Irfan’s Weblog














Have your say,We have no comments yet.