1 前提:已安装svn,假设已有版本库名称为 :share
2 安装perl并重新启动。
下载并安装 ActivePerl-5.14.2.1402-MSWin32-x86-295342.msi 下载地址 http://www.perl.org/get.html
默认安装路径为:C:\Perl
3 分别安装Authen-sasl和MIME::Lite模块
打开cmd 进入C:\Perl
c:\Perl>ppm install mime::lite
c:\Perl>ppm install authen-sasl
如果以上模块没有安装成功会报错误信息“503badsequenceofcommands”和“SMTP Error: Need MIME::Base64 and Authen::SASL todo auth”。
4 创建post-commit.bat 脚本
以版本库“share”为例子:进入版本库所在目录 ..\share\hooks\
新建post-commit.bat,或者复制“post-commit.tmpl” 为“post-commit.bat”
在svn commit 后调用post-commit.bat时,会传给此脚本两个参数,“repos” 和“rev” 依次代表发生修改的版本库路径和提交后的版本号。
post-commit.bat只起到将这两个参数和其他发送邮件发送配置传递给 commit-email.pl的作用。 所以下面一句就够了,详细内容参见“post-commit.tmpl”
==============post-commit.bat内容==================
内容含义:
2 安装perl并重新启动。
下载并安装 ActivePerl-5.14.2.1402-MSWin32-x86-295342.msi 下载地址 http://www.perl.org/get.html
默认安装路径为:C:\Perl
3 分别安装Authen-sasl和MIME::Lite模块
打开cmd 进入C:\Perl
c:\Perl>ppm install mime::lite
c:\Perl>ppm install authen-sasl
如果以上模块没有安装成功会报错误信息“503badsequenceofcommands”和“SMTP Error: Need MIME::Base64 and Authen::SASL todo auth”。
4 创建post-commit.bat 脚本
以版本库“share”为例子:进入版本库所在目录 ..\share\hooks\
新建post-commit.bat,或者复制“post-commit.tmpl” 为“post-commit.bat”
在svn commit 后调用post-commit.bat时,会传给此脚本两个参数,“repos” 和“rev” 依次代表发生修改的版本库路径和提交后的版本号。
post-commit.bat只起到将这两个参数和其他发送邮件发送配置传递给 commit-email.pl的作用。 所以下面一句就够了,详细内容参见“post-commit.tmpl”
==============post-commit.bat内容==================
C:\Perl\bin\perl.exe ..\commit-email.pl %1 %2 receiver@***.com --from send@***.com -l ..\log.txt -s " 邮件标题"
===============================================
内容含义:
C:\Perl\bin\perl.exe 为perl安装路径
..\commit-email.pl 为commit-email.pl脚本路径,如果后面找不到路径就填写绝对路径。
1% :“repos”
2%:“rev”
receiver@*** :收件人地址
--from send@***.com 发件人地址,--from必须的
-l ..\log.txt log文件地址 可选的的
-s " 邮件标题" 设置默认邮件主题
5 编辑 commit-email.pl脚本
下载commit-email.pl 脚本 http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/commit-email.pl.in
commit-email.pl脚本存放路径请与上面的路径一致。
修改内容:
5.1 找到my ($sendmail, $smtp_server修改为:my ($sendmail, $smtp_server, $username, $passwd);
5.2 可以注释掉sendmail,并修改或增加以下变量为真实信息。
#$sendmail = "/usr/sbin/sendmail";
$smtp_server = "×××××××"; 邮件服务器的 域名或ip
$username = "×××××"; 发送邮箱帐号
$passwd = "×××××"; 发送邮箱密码
my $svnlook = "..\\Subversion Server\\svnlook.exe"; svnlook的路径
5.3 将下面两个变量改1
my $no_diff_deleted = 1;
my $no_diff_added = 1;
5.4 在
my $smtp = Net::SMTP->new($smtp_server)
or die "$0: error opening SMTP session to `$smtp_server': $!\n";
后面增加:
handle_smtp_error($smtp, $smtp->auth("$username","$passwd"));
通过以上设置邮件就可以正常发送了。可以通过修改版本库内容来触发或者直接commit-email.pl 参数来运行脚本。
6 支持中文显示
修改commit-email.pl只需要将UTF-8改为GB2312即可。
#push(@head, "Content-Type: text/plain; charset=UTF-8\n");
push(@head, "Content-Type: text/plain; charset=GB2312\n");
因为中文显示,在网络找了很久,改字符集,在程序中做转换,都不行,就直接在客户端改了下编码就没问题了。
标题的中文显示,只要改下上面那行就行了。
..\commit-email.pl 为commit-email.pl脚本路径,如果后面找不到路径就填写绝对路径。
1% :“repos”
2%:“rev”
receiver@*** :收件人地址
--from send@***.com 发件人地址,--from必须的
-l ..\log.txt log文件地址 可选的的
-s " 邮件标题" 设置默认邮件主题
5 编辑 commit-email.pl脚本
下载commit-email.pl 脚本 http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/commit-email.pl.in
commit-email.pl脚本存放路径请与上面的路径一致。
修改内容:
5.1 找到my ($sendmail, $smtp_server修改为:my ($sendmail, $smtp_server, $username, $passwd);
5.2 可以注释掉sendmail,并修改或增加以下变量为真实信息。
#$sendmail = "/usr/sbin/sendmail";
$smtp_server = "×××××××"; 邮件服务器的 域名或ip
$username = "×××××"; 发送邮箱帐号
$passwd = "×××××"; 发送邮箱密码
my $svnlook = "..\\Subversion Server\\svnlook.exe"; svnlook的路径
5.3 将下面两个变量改1
my $no_diff_deleted = 1;
my $no_diff_added = 1;
5.4 在
my $smtp = Net::SMTP->new($smtp_server)
or die "$0: error opening SMTP session to `$smtp_server': $!\n";
后面增加:
handle_smtp_error($smtp, $smtp->auth("$username","$passwd"));
通过以上设置邮件就可以正常发送了。可以通过修改版本库内容来触发或者直接commit-email.pl 参数来运行脚本。
6 支持中文显示
修改commit-email.pl只需要将UTF-8改为GB2312即可。
#push(@head, "Content-Type: text/plain; charset=UTF-8\n");
push(@head, "Content-Type: text/plain; charset=GB2312\n");
因为中文显示,在网络找了很久,改字符集,在程序中做转换,都不行,就直接在客户端改了下编码就没问题了。
标题的中文显示,只要改下上面那行就行了。