Transactional Email MailChimp Helper Functions
Project description
Documentation
This is a Mandrill/Transactional Email MailChimp helper function package.
There are 5 functions available.
- list_all_templates
- template_merge_tags
- send_template
- send_template_attachment
- retrieve_data
Explanation
list_all_templates(api_key)
Given a valid API key (string), the function will return a list of template slugs and names.
Example:
api_key = "abcd1234567" list_of_templates = list_all_templates(api_key) # list_of_templates could contain: # [ {'slug': 'example-template', 'name': 'Example Template'} ]
template_merge_tags(api_key, template_name, merge_language)
Given a valid API key (string), template name or slug (string), and specified merge tag language (string), the function will return a list of merge tags in that template. However, there may be some merge tags that will be addressed somewhere else. Thus, do not need to be defined in global_merge_vars or merge_vars.
Example:
api_key = "abcd1234567" template_name = "example-template" # can also be "Example Template" merge_language = "mailchimp" # or "handlebars" list_of_merge_tags = template_merge_tags(api_key, template_name, merge_language) # list_of_merge_tags could contain: # {'merge_tags': ['subject', 'fullname', 'activity']}
'subject' will be defined somewhere else, so it does not need to be defined under global_merge_vars or merge_vars (this is applicable to every template)
send_template(api_key, template_name, fields)
Given a valid API key (string), template name or slug (string), and fields (struct), the function will return Mandrill's API JSON response.
Example:
api_key = "abcd1234567" template_name = "example-template" # can also be "Example Template" fields = { 'subject': 'This is an example', 'from_email': 'example@example.com', 'from_name': 'Example Name', 'to': [ { 'email': 'rcpt@example.com', 'name': 'Example Rcpt', 'type': 'to' #type as is }, { 'email': 'rcpt2@example.com', 'name': 'Example Rcpt2', 'type': 'to' #type as is } ], 'reply-to': 'replyto@example.com', 'global_merge_vars': [ { 'name': 'merge tag name', 'content': 'replace merge tag with' } ], 'merge_tags': [ { 'rcpt': 'rcpt2@example.com', 'vars': [ { 'name': 'merge tag name', 'content': 'replace merge tag content' } ] } ], 'merge_language': 'mailchimp' } response = send_template(api_key, template_name, fields) # response could contain: # [ # {'email': 'rcpt@example.com', 'status': 'sent', '_id': '12349853'}, # {'email': 'rcpt2@example.com', 'status': 'sent', '_id': '63313685'} # ]
not every attribute is required (ex: just sending generic info to everyone, so don't need 'merge_vars')
If the attribute is not needed, you can simply delete it in its entirety.
'global_merge_vars' vs 'merge_vars' :: one will replace the merge tags with the same info for everyone, and the other will override with specific info to a certain recipient (in the case above, Example Rcpt2)
'merge_language' must be either 'mailchimp' or 'handlebars', this just depends on what your template is using |MERGETAG| (mailchimp) or {{MERGETAG}} (handlebars)
send_template_attachment(api_key, template_name, fields)
Similar to send_template, but with an additional attribute in 'fields'
Example:
api_key = "abcd1234567" template_name = "example-template" # can also be "Example Template" fields = { 'subject': 'This is an example', 'from_email': 'example@example.com', 'from_name': 'Example Name', 'to': [ { 'email': 'rcpt@example.com', 'name': 'Example Rcpt', 'type': 'to' #type as is }, { 'email': 'rcpt2@example.com', 'name': 'Example Rcpt2', 'type': 'to' #type as is } ], 'reply-to': 'replyto@example.com', 'global_merge_vars': [ { 'name': 'merge tag name', 'content': 'replace merge tag with' } ], 'merge_tags': [ { 'rcpt': 'rcpt2@example.com', 'vars': [ { 'name': 'merge tag name', 'content': 'replace merge tag content' } ] } ], 'merge_language': 'mailchimp', 'attachments': [ { 'name': 'myfile.txt' }, { 'name': 'myimage.png' } ] } response = send_template_attachment(api_key, template_name, fields) # response could contain: # [ # {'email': 'rcpt@example.com', 'status': 'sent', '_id': '12349853'}, # {'email': 'rcpt2@example.com', 'status': 'sent', '_id': '63313685'} # ]
The same comments from send_template apply. If the attribute is not needed, you can simply delete it in its entirety.
'attachments' can support any file type, although, images will be sent as an attachment, not an embedded image.
This works by using base64 to convert the file into a base64-encoded string, which is then sent through Mandrill's API.
retrieve_data(api_key, query)
Given a valid API key (string) and a query (struct), the function returns an array of matching messages.
Example:
api_key = "abcd1234567" message = { 'query': 'rcpt@example.com', 'date_from': '2020-06-29', 'date_to': '2020-06-30', 'tags': [ ] 'limit': 100 } matching_msgs = retrieve_data(api_key, messgae) # matching_msgs could contain: # [ # { # a bunch of fields that Mandrill's API returns per matching message # } # ]
none of the attributes in 'message' are required, but they help narrow the returned results to messages that are more relevant to what you're looking for. Please note how the 'date_from' and 'date_to' strings are formatted.
If the attribute is not needed, you can simply delete it in its entirety.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ac_imandrill_periship-0.0.9.tar.gz
.
File metadata
- Download URL: ac_imandrill_periship-0.0.9.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d3299a7d95e2640d19048226913a4ac179287020baa65f95887e6f47da908fc |
|
MD5 | 38dae535f4ce819de26c3930bb57d66f |
|
BLAKE2b-256 | 254d778e191e4086e7dd5ebc71624c730e508cdffab14d5a1f040134b55741b3 |
File details
Details for the file ac_imandrill_periship-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: ac_imandrill_periship-0.0.9-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0729ac874f456daae68766cb64a6e5b47ad985aaca985f644ef7b07879d86f90 |
|
MD5 | e917383efd00411f3ce8045d2fb61c97 |
|
BLAKE2b-256 | 80ee892bab51c1076dd12e916ad33a7276da19a33a0f13370c42cce51755b797 |