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']
25 def email (subject, text, to, cc = None):
26 """Create a mime-message that will render HTML in popular
27 MUAs, text in better ones"""
32 out = cStringIO.StringIO() # output buffer for our message
33 txtin = cStringIO.StringIO(text)
35 writer = MimeWriter.MimeWriter(out)
37 # set up some basic headers... we put subject here
38 # because smtplib.sendmail expects it to be in the
41 writer.addheader("Subject", subject)
42 writer.addheader("To", to)
43 if cc: writer.addheader("CC", cc)
44 writer.addheader("MIME-Version", "1.0")
46 # start the multipart section of the message
47 # multipart/alternative seems to work better
48 # on some MUAs than multipart/mixed
50 writer.startmultipartbody("alternative")
53 # the plain text section
55 subpart = writer.nextpart()
56 subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
57 pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
58 mimetools.encode(txtin, pout, 'quoted-printable')
61 # Now that we're done, close our writer and
62 # return the message body
68 #server = smtplib.SMTP(MTA)
69 #server.sendmail(FROM, (to,cc), msg)
72 if __name__=="__main__":
75 id = siteId("alice.cs.princeeton.edu")
77 email('TEST', emailTxt.mailtxt.STANDARD % {'hostname': "ALICE.cs.princeton.edu"}, "tech-" + id + "@sites.planet-lab.org")