邮件接收脚本(电子邮件通知) [英] post-receive script for windows (email notification)

查看:679
本文介绍了邮件接收脚本(电子邮件通知)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows机器上创建了一个裸(中央)存储库。我的同事和我现在正在使用这个存储库。我希望git在更新时发送电子邮件通知。我知道我们需要在 post-receive 钩子中编写一些脚本,并配置 mailinglist emailprefix 属性。但是我需要的是脚本(在post-receive中),它在Windows机器中发送邮件。



注意:这里有一个类似的问题。但答案是'该做什么?'而不是'怎么办?
如果我的回购是在Windows机器上,我可以让git发送带有post-receive-email脚本的电子邮件吗?



预先感谢您。 就像股票收到后的示例脚本的注释中所描述的一样,但是Git for Windows提供了msmtp而不是sendmail。如果您将来自 contrib / hooks 的贡献脚本粘贴到post-receive脚本,你只需要做一些改变。首先,您需要指定一个smtp服务器,因此我建议添加配置变量sendemail.smtpserver并将其设置为您的服务器的名称。如果您需要身份验证等,请查找配置变量,然后修改脚本以使用它们。



在粘贴的电子邮件脚本中,将 sendmail 与msmtp如下

  send_mail()
{
如果[-n$ envelopesender];然后
msmtp --host =$ smtpserver-t -f$ envelopesender
else
msmtp --host =$ smtpserver-t
fi
}

最后,接近文件末尾的部分是读取git config变量所以添加一个新行来读取服务器值:
$ b $ $ p $ smtpserver = $(git config sendemail.smtpserver)
code>

通过这两项更改,脚本可以正常工作,将邮件发送到 hooks.mailinglist推送时帐户。


I've created a bare (central) repository on a windows machine. My colleagues and myself are now using this repository. I want the git to send out an email notification whenever it's updated. I know that we need to write some script in post-receive hook and configure mailinglist and emailprefix properties. But what i need is the script (in post-receive), which sends out a mail in windows machine.

Note: There is a similar question asked here. But the answer is 'what to do?' not 'how to do?. Can I have git send out an email with the post-receive-email scripts if my repo is on a Windows machine?

Thanks in advance.

解决方案

You can do this pretty much as described in the comments in the stock post-receive sample script but with the exception that Git for Windows provides msmtp and not sendmail. If you paste the contributed script from contrib/hooks into the post-receive script you then just need to make a couple of changes. Firstly, you will need to specify a smtp server so I suggest adding the config variable sendemail.smtpserver and set it to the name of your server. If you need authentication and so on then look up the config variables for those and ammend the script to make use of them.

In the pasted in email 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 server values:

smtpserver=$(git config sendemail.smtpserver)

With those two changes in place, the script works fine for me, sending mail to the hooks.mailinglist account on push.

这篇关于邮件接收脚本(电子邮件通知)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆