3 # Copyright (c) 2004 The Trustees of Princeton University (Trustees).
5 # Faiyaz Ahmed <faiyaza@cs.princeton.edu>
13 FROM="support@planet-lab.org"
15 XMLRPC_SERVER = 'https://www.planet-lab.org/PLCAPI/'
18 api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
19 anon = {'AuthMethod': "anonymous"}
20 site_id = api.AnonAdmQuerySite (anon, {"node_hostname": hostname})
22 loginbase = api.AnonAdmGetSites (anon, site_id, ["login_base"])
23 return loginbase[0]['login_base']
27 def email (subject, text, to, cc = None):
28 """Create a mime-message that will render HTML in popular
29 MUAs, text in better ones"""
34 out = cStringIO.StringIO() # output buffer for our message
35 txtin = cStringIO.StringIO(text)
37 writer = MimeWriter.MimeWriter(out)
39 # set up some basic headers... we put subject here
40 # because smtplib.sendmail expects it to be in the
43 writer.addheader("Subject", subject)
44 writer.addheader("To", to)
45 if cc: writer.addheader("CC", cc)
46 writer.addheader("MIME-Version", "1.0")
48 # start the multipart section of the message
49 # multipart/alternative seems to work better
50 # on some MUAs than multipart/mixed
52 writer.startmultipartbody("alternative")
55 # the plain text section
57 subpart = writer.nextpart()
58 subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
59 pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
60 mimetools.encode(txtin, pout, 'quoted-printable')
63 # Now that we're done, close our writer and
64 # return the message body
70 server = smtplib.SMTP(MTA)
71 server.sendmail(FROM, (to,cc), msg)
74 if __name__=="__main__":
78 email('DISREGARD', emailTxt.mailtxt.STANDARD % {'hostname': "ALICE.cs.princeton.edu"}, "tech-" + siteId("alice.cs.princeton.edu") + "@sites.planet-lab.org")