Post-receive script for windows (email notification)

I created a bare (central) repository on a Windows machine. Now my colleagues and I use this repository. I want git to send an email notification whenever it is updated. I know that we need to write some script in the post-receive hook and configure the mailinglist and emailprefix . But I need a script (in post-receive) that sends mail on a Windows machine.

Note. A similar question is asked here. But the answer is "what to do?" not 'how to do it ?. Can I git send an email using post-receive-email scripts if my repo is on a Windows machine?

Thanks in advance.

+4
source share
1 answer

You can do this pretty much as described in the comments in the post post-receive script example, but with the exception that Git for Windows provides msmtp, not sendmail. If you enter the script tab from contrib / hooks into a post-receive script, you just need to make a couple of changes. First, you need to specify the SMTP server, so I suggest adding the sendemail.smtpserver configuration variable and setting it to your server name. If you need authentication, etc., then find the configuration variables for them and compensate for the script to use them.

In the email pasted script - replace sendmail with msmtp as follows

 send_mail() { if [ -n "$envelopesender" ]; then msmtp --host="$smtpserver" -t -f "$envelopesender" else msmtp --host="$smtpserver" -t fi } 

And finally, near the end of the file is a section that reads in the Git config variable, so add a new line to read the server values:

 smtpserver=$(git config sendemail.smtpserver) 

With these two changes in place, the script works fine for me, sending mail to the hooks.mailinglist account when clicked.

+3
source

All Articles