0

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

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

4

1 回答 1

0

我就此事联系了 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()
于 2017-03-16T23:02:16.440 回答