如何轻松发送 Campaign Monitor 模板的预览电子邮件?

How can I easily send a preview email for a Campaign Monitor template?

我已经将我们自己的一些电子邮件模板迁移到 Campaign Monitor 的系统中。我想编写一个例程来发送所选模板的预览电子邮件。我正在使用 Python (https://github.com/campaignmonitor/createsend-python).

看来我必须创建一个具有 send_preview https://github.com/campaignmonitor/createsend-python/blob/master/createsend/campaign.py#L87 功能的活动。但是,我还需要创建一个列表,以便仅将活动对象用于此预览目的。这感觉不必要/尴尬。我觉得我正在掉进兔子洞。有没有更简单的发送预览邮件的方法?

我就此事联系了 Campaign Monitor 支持,并收到了创建活动所需的信息和用于发送测试电子邮件的列表。我想虽然列表可以是空的,因为您在 send_preview 期间明确指定了一封电子邮件。在我的例子中,我将 GUID 插入到列表和活动的名称中以保证名称的唯一性。

发送电子邮件后,您可以立即删除这些临时活动和列表。请务必先删除广告系列,因为您无法删除与广告系列相关联的列表。

cm_token = {'api_key': settings.CAMPAIGN_MONITOR_ADMIN_API_KEY}
campaign_monitor = CreateSend(cm_token)
cm_list = List(cm_token)
list_id = cm_list.create(email_client_id, "Temporary empty list for preview {}".format(uuid.uuid1()), None, None, None)
# cm_subscribers = []
# for recipient in recipient_list:
#     cm_subscriber = Subscriber(cm_token)
#     cm_subscriber.add(list_id, recipient[0], "Preview recipient {}".format(uuid.uuid1()), None, None)
#     cm_subscribers.append(cm_subscriber)
cm_campaign = Campaign(cm_token)
cm_campaign.create_from_template(
    customer_account.email_client_id,
    subject,
    "Temporary campaign for preview {}".format(template.id),  # name
    from_email,  # from_name
    from_email,
    from_email,  # reply_to
    [list_id],  # list_ids
    None,  # segment_ids
    template.template_id,
    {}  # template_content
)
cm_campaign.send_preview(recipient_list[0])
# delete temporary list and campaign
cm_campaign.delete()
cm_list.delete()