$ cat mailer.py #!/usr/bin/python # -*- coding:utf-8 -*-
import smtplib import sys import os from email.mime.multipart import MIMEMultipart from email.MIMEText import MIMEText from subprocess import Popen, PIPE
smtp_hostname="smtp.mailserver.com:port" smtp_username="mailer@mailserver.com" smtp_password="password" toaddrs = ['user1@mailserver.com','user2@mailserver.com','user2@mailserver.com'] project_name = os.path.basename(sys.argv[1]) subject = "["+project_name+"]"+" svn repository update required" content = project_name + "\n" + "rev : " + sys.argv[2]+ "\n"
cmd_1 = ['svnlook','changed','-r',sys.argv[2],sys.argv[1]] proc = Popen(cmd_1, stdout=PIPE) difflist = proc.stdout.read()
cmd_2 = ['svnlook','info','-r',sys.argv[2],sys.argv[1]] proc = Popen(cmd_2, stdout=PIPE) svninfo = proc.stdout.read()
content = "[" + project_name + "]\n" + "rev : " + sys.argv[2]+ "\n" + difflist +"\n" + svninfo
msg = MIMEMultipart() msg['From'] = smtp_username msg['To'] = ", ".join(toaddrs) msg['Subject'] = subject msg.attach(MIMEText(content,_charset='utf-8'))
print msg.as_string()
server = smtplib.SMTP_SSL(smtp_hostname) server.login(smtp_username,smtp_password) server.sendmail(smtp_username, toaddrs, msg.as_string()) server.quit() |