事务性电子邮件MailChimp Helper函数

ac-imandrill-periship的Python项目详细描述


文件

这是一个Mandrill/Transactional Email MailChimp helper函数包。在

有5个功能可用。在

  • 列出所有模板
  • 模板合并标记
  • 发送模板
  • 发送模板附件
  • 检索\u数据

解释

list_所有模板(api密钥)

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_标记(api密钥、模板名称、合并语言)

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密钥、模板名称、字段)

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_附件(api密钥、模板名称、字段)

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.

检索数据(api密钥,查询)

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.

Github-flavored Markdown

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
virtualbox无法从java移动共享文件夹中的文件   java如何连接Android 4.3.5(GA)的apache HttpClient库?   片段中的java Recyclerview未立即显示警报对话框结果   javac(n,r)计算器程序不工作   java使用BooleanQuery还是编写更多索引?   如何在java中设置y/n循环?   java不兼容的通用通配符捕获   java如何在安卓xml中编写数据绑定时的三元操作条件   java如何使用FileDialog?   java如何创建单元测试来检测是否有人使用错误的编码编辑了文件?   java如何从唯一的字符串生成唯一的int?   java gradletomcatplugin:log4j:WARN找不到记录器的附加程序   java我的动态编程解决方案(Kefa和第一步)在codeforces中有什么问题?   java每天更新两个数据库,使它们都包含相同的有效数据集   java如何检查给定的时间是否在时间限制之间   java在单个json POST上保存父级和子级   java如何获取Solr字段类型