ゲストOS(VirtualBox上のUbuntu)のsubversionで管理されているファイルをホストOSのTortoiseSVNでコミットしたらメールを送信する

ゲストOS(VirtualBox上のUbuntu)のsubversionで管理されているファイルをホストOSのTortoiseSVNでコミットしたらメールを送信する

■mailer.conf mailer.pyを取得
下記URLにアクセスする
http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/mailer/
下記2ファイルをダウンロードして /home/svn/test/hooks 直下に配置する
 mailer.conf.example
 mailer.py
mailer.conf.example を mailer.conf にリネームする。

■mailer.confの設定値を修正

[general]
smtp_username = ****** (gmailのアカウント名)
smtp_password = ****** (gmailのパスワード)
smtp_use_ssl = true
smtp_use_tls = 1
[defaults]
commit_subject_prefix = [commit] my_project
from_addr = ******@gmail.com
to_addr = ******@gmail.com
reply_addr = ******@gmail.com
generate_diffs = none
commit_url = http://localhost:8080/svn/test

■mailer.pyの「SMTPサーバへの認証処理」を修正

class SMTPOutput(MailedOutput):
(省略)
def finish(self):
	server = smtplib.SMTP("smtp.gmail.com",587)
	server.ehlo()
	server.starttls()
	server.login("******@gmail.com","****** (gmailのパスワード)")
	
	if self.cfg.is_set('general.smtp_username'):
		server.login(self.cfg.general.smtp_username,
					self.cfg.general.smtp_password)
		server.sendmail(self.from_addr, self.to_addrs,self.buffer.getvalue())
		serer.quit()

■コミットしたらmailer.pyが起動するように修正
既存の post-commit.tmpl を別名 post-commit でコピーする。
cp post-commit.tmpl post-commit
post-commitの最後の行に下記を追記

REPOS="$1"
REV="$2"

/usr/bin/python /home/svn/test/hooks/mailer.py commit "$REPOS" "$REV"

■実行権限を付与
よくわからんので777する
chmod 777 mailer.conf
chmod 777 mailer.py
chmod 777 post-commit

■動作確認
コミットする
f:id:sho_japan:20150607154552j:plain

メール受信確認
f:id:sho_japan:20150607154553j:plain

■参考にしたサイト
http://stackoverflow.com/questions/12030179/issue-sending-email-with-python
https://www.pythonanywhere.com/forums/topic/1961/