事务性电子邮件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第三方库


热门话题
datetime如何使用JodaTime在Java中设置时间属性   java固定算法的性能时间   java如何从JMenu中获取所选项以更改文本区域的文本颜色?   java配置单元UDF传递数组<string>作为参数   javaapachebeam和BigQuery   java与PrintWriter之间的差异。printf和PrintWriter。格式方法   继承如何处理按Java版本更改的导入,以及在多个版本上编译   xml java。lang.noClassDefFoundant生成错误   java如何使用包含映射的JSON发送POST请求?   java如何在任何应用程序的JAR文件中绑定MySql数据库?   Java脚本解释器   sslhttpclientjava。网SocketException:未实现未连接的socket   java如何为Android应用程序创建类似于Cron作业的东西   java JButton+radiobox+复选框   java内存管理将文件写入内存   java这是计算对象实例的有效方法吗?   用于死锁情况的java代码?   JavaSpring容器作为新实体插入,而不是存储在表中