-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandrill.py
28 lines (25 loc) · 925 Bytes
/
mandrill.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
import json
from bson import json_util
from settings import MANDRILL_APIKEY, MANDRILL_ENDPOINT
def send_with_template(form, contents, attachments):
form_fields = ["to"] #['subject', 'from_email', 'from_name', 'to']
message = { k:form.get(k, None) for k in form_fields }
message.update(
{'global_merge_vars': [{ 'name':"f_"+key, 'content':value[0]} for key, value in contents.iteritems()],
'attachments': attachments}
)
data = {
'key': MANDRILL_APIKEY,
'template_name': form.get('mandrill_template', form['name']),
'template_content' :[],
'message': message
}
print "Sending"
print data
response = requests.post(
MANDRILL_ENDPOINT+"messages/send-template.json",
data=json.dumps(data, default=json_util.default)
)
print response
return response.json()