def send_mail_string(mailStr, base_url=None): if base_url is None: tglobals, tlocals = get_twill_glocals() base_url = tglobals['base_url'] receiverURL = "%s/send_listen_mail" % base_url.rstrip("/") tglobals, tlocals = get_twill_glocals() ctx = tglobals.copy() ctx.update(tlocals) mailStr = substitute_vars(mailStr, ctx) mail = email.message_from_string(mailStr) body = mail.get_payload() sender = mail['From'] recipient = mail['To'] subject = mail['Subject'] log_warn("sending email: Subject: '%s'; From: '%s'; To: '%s'" % ( subject, sender, recipient)) send(receiverURL, mailStr)
def send_mail_string(mailStr, base_url=None): if base_url is None: tglobals, tlocals = get_twill_glocals() base_url = tglobals['base_url'] receiverURL = "%s/send_listen_mail" % base_url.rstrip("/") tglobals, tlocals = get_twill_glocals() ctx = tglobals.copy() ctx.update(tlocals) mailStr = substitute_vars(mailStr, ctx) mail = email.message_from_string(mailStr) body = mail.get_payload() sender = mail['From'] recipient = mail['To'] subject = mail['Subject'] log_warn("sending email: Subject: '%s'; From: '%s'; To: '%s'" % (subject, sender, recipient)) send(receiverURL, mailStr)
def fake_form(filename): """ Subsitite variables in the file given and make the current location the result. eg this can be used to generate a form submitting "someinput" to an arbitrary url using a local file like <html> <head> </head> <body> <form action="${form_action}"> <input name="someinput" /> </form> </body> </html> """ search_path = flunc.options.search_path form_template_fn = os.path.join(search_path, filename) fake_form_template = open(form_template_fn).read() lookup = get_twill_glocals()[0] fake_form_data = substitute_vars(fake_form_template, lookup) fake_form = NamedTemporaryFile(mode="w", prefix="flunc-", suffix=".html") fake_form.write(fake_form_data) fake_form.flush() fake_form_url = "file://%s" % fake_form.name twill.commands.go(fake_form_url)