• Home »
  • »
  • How to Get Email Notifications from Subversion on Commits

How to Get Email Notifications from Subversion on Commits

I recently was asked by some guys on my team if it was possible to get email notifications for every commit to svn with a description of what was removed, what was committed and a diff if possible. Now it seems like this would be easy and maybe even built into subversion so I checked into that first. There was a ruby script which can be made as a hook-script which is supposed to send email notifications. I spent quite some time trying to get it to work and didn’t have much luck so I decided to research some other options. I ran across a python program which was written specifically for this task called svnmailer.

Below I will detail the steps needed to get svnmailer working on your system:

The first thing we need is to make sure we have pysvn:


  1. root@redmine:~# python
  2. Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
  3. [GCC 4.3.3] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import svn
  6. >>>

If you do not get a error it means you have pysvn installed and it is working. If you get some sort of error you may need to download and install it.

I used 1.5 at the time of this article which I grabbed from here

Lets install it:


  1. root@redmine:~#tar xvzf pysvn-1.5.0.tar.gz
  2. root@redmine:~#cd pysvn-1.5.0/Source
  3. root@redmine:~#python setup.py configure
  4. root@redmine:~#mkdir /usr/lib/python2.4/site-packages/pysvn
  5. root@redmine:~#cp pysvn/__init__.py /usr/lib/python2.5/site-packages/pysvn
  6. root@redmine:~#cp pysvn/_pysvn.so /usr/lib/python2.5/site-packages/pysvn

Once you get that installed you should be able to run the imort svn command again and this time it will return to the python prompt with no errors.

NOTE: Pysvn maybe available in the package manger of your distro so check that first.

The next thing we need to do is download and install svnmailer:

Go here and download the version of svnmailer you want to use. I used 1.0.8 since it was the most recent stable version.

Lets install it:


  1. root@redmine:~#tar xvzf svnmailer-1.0.8.tar.gz
  2. root@redmine:~#cd svnmailer-1.0.8
  3. root@redmine:~#python setup.py install

NOTE: Once again you package management system may have svnmailer so check that first

I am assuming that you already have a repo installed so for the sake of this article we will pretend the repo is called “myrepo” and is located at /var/svn/

The next thing to do is create the hook script:


  1. cd /var/svn/myrepo/hooks

If there is a file called post-commit open it up in a editor, if it is not there simply create it.

Place the following text in the file:


  1. #!/bin/sh
  3. CONFIG="/etc/svn-mailer.conf"
  4. MAILER="/usr/bin/svn-mailer"
  6. # These are passed in by subversion
  7. REPOS="$1"
  8. REV="$2"
  10. "${MAILER}" --commit \
  11.             --config "${CONFIG}" \
  12.             --repository "${REPOS}" \
  13.             --revision "${REV}" \

Save this file and then give it the following permissions:


  1. chmod 755 post-commit

Next we need to configure the conf file for svnmailer:

I created mine in /etc/svn-mailer.conf. Create the file and paste in the following text:


  1. [general]
  2. # the diff command to be used ... just copy it...
  3. diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s
  4. # the sendmail location
  5. mail_command = /usr/sbin/sendmail
  7. [mymodule]
  8. for_paths = myrepo/.*
  9. # the subject of the email
  10. commit_subject_prefix = "SVN COMMIT:"
  11. # From address in the mail
  12. from_addr = svnadmin@question-defense.com
  13. # To address ...
  14. to_addr = example@question-defense.com
  16. [defaults]
  17. # this part of the config apply for all the other module
  18. # Default From address template
  19. from_addr = svnadmin@question-defense.com
  20. # the subject of the email
  21. commit_subject_prefix = "SVN COMMIT:"
  22. to_addr = example@question-defense.com
  23. generate_diffs = add copy modify
  24. suppress_deletes = yes

Obviously you will need to change the path to the repo, the from email and the send to email to fit your set up.

Next lets test our set up:


  1. cd /var/sv/myrepo/hooks
  2. ./post-commit /var/svn/myrepo/ 366

You will need to replace the /path/to/repo ad the revision number to work for you but once this command is run, subversion should get a email with the contents of revision 366.

Now once a commit is made you will get an email . You can also add more than one email on the to_addr line, just separate each one with a space.

Version Control With Subversion for Subversion 1.6: The Official Guide And Reference Manual (Paperback)

List Price: $30.00
New From: $47.63 USD In Stock
Used from: $0.52 USD In Stock

Version Control with Subversion (Paperback)

List Price: $39.99 USD
New From: $19.95 USD In Stock
Used from: $0.98 USD In Stock