![]()
#!/usr/bin/python
import subprocess
import smtplib, sys, MimeWriter, StringIO, base64
import os
def get_bugzs():
p = subprocess.Popen('searchbugz > /tmp/bugz.txt', shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()
def mail(serverURL=None, port=None, sender='', to='', subject='', text=''):
"""
Usage:
mail(
'smtp.gmail.com', 587, 'comprookie2000@gmail.com',
'david@linuxcrazy.com', 'Bug Wranglers', 'Current Bugs:')
"""
message = StringIO.StringIO()
writer = MimeWriter.MimeWriter(message)
writer.addheader('Subject', subject)
writer.startmultipartbody('mixed')
# start off with a text/plain part
part = writer.nextpart()
body = part.startbody('text/plain')
body.write(text)
# now add an attachment
part = writer.nextpart()
part.addheader('Content-Transfer-Encoding', 'base64')
body = part.startbody('text/plain')
base64.encode(open('/tmp/bugz.txt', 'rb'), body)
# finish off
writer.lastpart()
# send the mail
smtp = smtplib.SMTP('smtp.gmail.com', 587)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login('yourname@gmail.com', 'yourpw')
smtp.sendmail(sender, to, message.getvalue())
smtp.quit()
if __name__ == "__main__":
get_bugzs()
mail(
'smtp.gmail.com', 587, 'from@gmail.com',
'to@someone.com', 'Bug Wranglers', 'Current Bugs:')
os.remove('/tmp/bugz.txt')
David Abbott - david at linuxcrazy dot com