|
1 | | -# Simple Mailjet APIv3 wrapper |
| 1 | + |
| 2 | + |
| 3 | +# Simple Mailjet APIv3 Python Wrapper |
2 | 4 |
|
3 | 5 | [doc]: http://dev.mailjet.com/guides/?python# |
4 | 6 | [api_doc]: https://github.com/mailjet/api-documentation |
@@ -68,15 +70,33 @@ result = mailjet.contact_getcontactslists.get(id=2) |
68 | 70 | ## Send an Email |
69 | 71 | ``` python |
70 | 72 |
|
71 | | -email = { |
72 | | - 'FromName': 'Mr Smith', |
73 | | - |
74 | | - 'Subject': 'Test Email', |
75 | | - 'Text-Part': 'Hey there!', |
76 | | - 'Recipients': [{'Email': 'your email here'}] |
| 73 | +from mailjet_rest import Client |
| 74 | +import os |
| 75 | +api_key = os.environ['MJ_APIKEY_PUBLIC'] |
| 76 | +api_secret = os.environ['MJ_APIKEY_PRIVATE'] |
| 77 | +mailjet = Client(auth=(api_key, api_secret), version='v3.1') |
| 78 | +data = { |
| 79 | + 'Messages': [ |
| 80 | + { |
| 81 | + "From": { |
| 82 | + |
| 83 | + "Name": "Mailjet Pilot" |
| 84 | + }, |
| 85 | + "To": [ |
| 86 | + { |
| 87 | + |
| 88 | + "Name": "passenger 1" |
| 89 | + } |
| 90 | + ], |
| 91 | + "Subject": "Your email flight plan!", |
| 92 | + "TextPart": "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!", |
| 93 | + "HTMLPart": "<h3>Dear passenger 1, welcome to Mailjet!</h3><br />May the delivery force be with you!" |
| 94 | + } |
| 95 | + ] |
77 | 96 | } |
78 | | - |
79 | | -mailjet.send.create(email) |
| 97 | +result = mailjet.send.create(data=data) |
| 98 | +print result.status_code |
| 99 | +print result.json() |
80 | 100 |
|
81 | 101 | ``` |
82 | 102 |
|
|
0 commit comments