How to debug / correctly setup git-multimail
<p>I would like to use <a href="https://github.com/git-multimail/git-multimail" rel="nofollow">git-multimail</a> as post receive hook in one of my git repositories (no gitolite used). Unfortunately, I cannot get it work, and I have hardly any experience using Python.</p>

<h2>What I did so far:</h2>

<ol>
<li>I added the following block to the <code>project.git/config</code> file:</li>
</ol>

<p>&nbsp;</p>

<pre><code>[multimailhook]
    mailingList = email@example.com
    from = email@example.com
    envelopeSender = email@example.com
    mailer = smtp
    smtpServer = smtp.mydomain.com
    smtpUser = myUser
    smtpPass = myPassword
</code></pre>

<p>Please note that I do not know whether "smtp", which is defined in the <code>mailer</code> variable, is installed on my machine.</p>

<ol start="2">
<li>I copied the current <code>git_multimail.py</code> file into <code>project.git/hooks</code>.</li>
<li>I created a <code>project.git/hook/post-receive</code> file with the following content. The file is executable, I copied this from <a href="https://github.com/git-multimail/git-multimail/blob/master/git-multimail/post-receive.example" rel="nofollow">https://github.com/git-multimail/git-multimail/blob/master/git-multimail/post-receive.example</a></li>
</ol>

<p>&nbsp;</p>

<pre><code>#! /usr/bin/env python

import sys
import os
import git_multimail

config = git_multimail.Config('multimailhook')

try:
    environment = git_multimail.GenericEnvironment(config=config)
    #environment = git_multimail.GitoliteEnvironment(config=config)
except git_multimail.ConfigurationException:
    sys.stderr.write('*** %s\n' % sys.exc_info()[1])
sys.exit(1)

mailer = git_multimail.choose_mailer(config, environment)

git_multimail.run_as_post_receive_hook(environment, mailer)
</code></pre>

<h2>What happens:</h2>

<p>When I push a change, a file <code>project.git/hooks/git_multimail.pyc</code> is created, but no email is sent.</p>

<p>Doing a configuration test using <code>GIT_MULTIMAIL_CHECK_SETUP=true python git_multimail.py</code> as described on <a href="https://github.com/git-multimail/git-multimail/blob/master/doc/troubleshooting.rst" rel="nofollow">https://github.com/git-multimail/git-multimail/blob/master/doc/troubleshooting.rst</a> tells me that <code>git-multimail seems properly set up</code></p>

<p>Is there a way to log something like an output of the script? What can I do to find out what is not working? Are there even errors in my files?</p>

<p>Thanks in advance.</p>

<p>OK guys, the error was probably as little as it could be. I did just one very little mistake in the post receive hook file: The <code>sys.exit(1)</code> command is not indented.</p>

<p>So, the WRONG version from my question:</p>

<pre><code>try:
    environment = git_multimail.GenericEnvironment(config=config)
except git_multimail.ConfigurationException:
    sys.stderr.write('*** %s\n' % sys.exc_info()[1])
sys.exit(1)
</code></pre>

<p>CORRECT is (compare last line):</p>

<pre><code>try:
    environment = git_multimail.GenericEnvironment(config=config)
except git_multimail.ConfigurationException:
    sys.stderr.write('*** %s\n' % sys.exc_info()[1])
    sys.exit(1)
</code></pre>

<p>Like I said, I hardly know Python, so I did not pay attention to the indents. After correcting this, the email was sent, so feel free to use the above steps as a little tutorial for setting up git-multimail the "easiest" way. (I did not find a tutorial for this exact solution.)</p>

python git githooks post-receive-email