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']
26 def slices(loginbase):
27 api = xmlrpclib.Server(XMLRPC_SERVER, verbose=False)
28 return api.SliceListNames (auth.auth, loginbase)
31 def email (subject, text, to):
32 """Create a mime-message that will render HTML in popular
33 MUAs, text in better ones"""
38 out = cStringIO.StringIO() # output buffer for our message
39 txtin = cStringIO.StringIO(text)
41 writer = MimeWriter.MimeWriter(out)
43 # set up some basic headers... we put subject here
44 # because smtplib.sendmail expects it to be in the
47 writer.addheader("Subject", subject)
48 if to.__class__ == [].__class__ :
49 writer.addheader("To", to[0])
51 for dest in to[1:len(to)]:
54 writer.addheader("CC", cc)
56 writer.addheader("To", to)
58 writer.addheader("MIME-Version", "1.0")
60 # start the multipart section of the message
61 # multipart/alternative seems to work better
62 # on some MUAs than multipart/mixed
64 writer.startmultipartbody("alternative")
67 # the plain text section
69 subpart = writer.nextpart()
70 subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
71 pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
72 mimetools.encode(txtin, pout, 'quoted-printable')
75 # Now that we're done, close our writer and
76 # return the message body
81 server = smtplib.SMTP(MTA)
82 server.sendmail(FROM, to, msg)
85 if __name__=="__main__":
88 id = siteId("alice.cs.princeton.edu")
91 #email('TEST', emailTxt.mailtxt.ssh % {'hostname': "ALICE.cs.princeton.edu"}, "tech-" + id + "@sites.planet-lab.org")
94 #email("TEST109", "THIS IS A TEST", ["faiyaza@cs.princeton.edu", "faiyaz@winlab.rutgers.edu", "faiyaza@gmail.com"])