#encoding:utf-8
import requests
import simplejson 
import urllib

url = "https://api.sendcloud.net/apiv2/mail/send"                         

API_USER = ''
API_KEY = ''

content = '''
  Dear %name%:

  Hello, your bill money: $ %money%.
'''

params = {                                                                      
    "apiUser": API_USER, 
    "apiKey" : API_KEY,                                             
    "from" : "sendcloud@sendcloud.org", 
    "fromName" : "SendCloud",                                                    
    #"to" : "test@ifaxin.com", # if use the xsmtpapi, the `to` is no need 
    "subject" : "SendCloud python common with xsmtpapi",                              
    "html": content,
}                                                                               

x_smtpapi = {
    "to": ["a@ifaxin.com",'b@ifaxin.com'],
    "sub": {
        "%name%": ['jack', 'rose'],
        "%money%": ['199', '299'],
    },
}

params['xsmtpapi'] = simplejson.dumps(x_smtpapi)

filename1 = "1.txt"
display_filename_1 = "aaa"

files = {
    "attachments" : (urllib.quote(display_filename_1), open(filename1, 'rb'),'application/octet-stream')
}

r = requests.post(url, files=files, data=params)
print r.text

