
comprookie2000
By: a guest on
Apr 3rd, 2009 | syntax:
Python | size: 1.34 KB | hits: 335 | expires: Never
#!/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, 'yourname@gmail.com', 'fromaddress@someaddress.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', 'passwd')
smtp.sendmail(sender, to, message.getvalue())
smtp.quit()
if __name__ == "__main__":
get_bugzs()
mail('smtp.gmail.com', 587, 'yourname@gmail.com','fromaddress@someaddress.com', 'Bug Wranglers', 'Current Bugs:')
os.remove('/tmp/bugz.txt')