Skip to content

Instantly share code, notes, and snippets.

@brendanc
Last active June 14, 2016 14:35
Show Gist options
  • Select an option

  • Save brendanc/7a1449112391339a18b9c705769d2e87 to your computer and use it in GitHub Desktop.

Select an option

Save brendanc/7a1449112391339a18b9c705769d2e87 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
import smtplib
import time
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
ACCOUNT_KEY = 'backend'
USERNAME = '[email protected]'
PASSWORD = '***'
def create_test():
xml = ''
with open('create-test.xml', 'r') as myfile:
xml=myfile.read().replace('\n', '')
url = 'https://' + ACCOUNT_KEY + '.litmus.com/emails.xml'
headers = {'Content-Type': 'application/xml'}
result = requests.post(url, data=xml, headers=headers, auth=(USERNAME, PASSWORD)).text
print result
soup = BeautifulSoup(result,"html.parser") # we're not parsing html here but that's ok
return (soup.test_set.id.string,soup.test_set.test_set_versions.test_set_version.url_or_guid.string)
def publish_test(test_id):
xml = '<?xml version="1.0" encoding="UTF-8"?><test_set><public_sharing>true</public_sharing><name>Look at me!!</name></test_set> '
url = 'https://' + ACCOUNT_KEY + '.litmus.com/tests/' + test_id + '.xml'
headers = {'Content-Type': 'application/xml'}
result = requests.put(url, data=xml, headers=headers, auth=(USERNAME, PASSWORD)).text
print result
soup = BeautifulSoup(result,"html.parser") # we're not parsing html here but that's ok
return soup.test_set.public_path.string
def send_email(to):
# build up the message object
msg = MIMEMultipart('alternative')
msg['Subject'] = 'Html email sample subject'
msg['From'] = "[email protected]"
msg['To'] = to
# set the plain text and html parts
plain = ""
html = ""
with open("html.html","r") as f_html:
html = f_html.read()
f_html.closed
with open("plain.txt","r") as f_plain:
plain = f_plain.read()
f_plain.closed
msg.attach(MIMEText(plain, 'plain'))
msg.attach(MIMEText(html, 'html'))
s = smtplib.SMTP('localhost')
s.sendmail("[email protected]", to, msg.as_string())
s.quit()
print "message sent successfully"
def main():
# create Litmus test
test = create_test()
# send your message to Litmus
print test[1]
send_email(test[1])
# optonal: wait 10s for test to complete
print "waiting 10s for tests to complete"
time.sleep(10)
# publish the test
url = publish_test(test[0])
print url
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment