【问题标题】:Batch sending and individual message ID with Mailgun使用 Mailgun 批量发送和单个消息 ID
【发布时间】:2013-10-27 10:45:15
【问题描述】:

我正在使用Mailgun 向客户列表发送付款提醒。

我最初的解决方案是使用他们的 REST API 向一组收件人 (batch sending) 发送电子邮件。像这样:

public static bool SendBatch(string From, Dictionary<string, Object> vars, string txtEmail, string htmlEmail)
{
    RestClient client = new RestClient();
    client.BaseUrl = "https://api.mailgun.net/v2";
    client.Authenticator =
            new HttpBasicAuthenticator("api",
                                       "my-mailgun-key");
    RestRequest request = new RestRequest();
    request.AddParameter("domain", "my-domain.tld.mailgun.org", ParameterType.UrlSegment);
    request.Resource = "{domain}/messages";
    request.AddParameter("from", From);
    foreach (KeyValuePair<string, Object> entry in vars)
    {
        request.AddParameter("to", entry.Key);
    }
    request.AddParameter("subject", "Payment option ready");
    request.AddParameter("text", txtEmail);
    request.AddParameter("html", htmlEmail);
    request.AddParameter("recipient-variables", vars.ToJSON());
    request.Method = Method.POST;
    client.Execute(request);
    return true;
}

(对于 ToJSON() 自定义扩展,请参阅 this blog post

这很好用。但是,现在我想跟踪打开。 documentation 声明使用 webhook(当用户打开电子邮件时获取 POST 数据的简单网页)我可以获得有关此操作的大量信息,包括一些很酷的数据,例如地理位置。

有两个值看起来很有希望:标签自定义变量。但是,这两个值都将在创建请求时包含在内,但在批量发送中这些值不起作用(它们将识别 batch 发送本身,而不是单个电子邮件。)

有没有办法为使用 Mailgun API 发送的每封电子邮件添加标识变量?我已经求助于发送单独的电子邮件,但是如果我必须将电子邮件发送到一个大列表,那将非常不方便。

【问题讨论】:

    标签: c# api batch-processing mailgun


    【解决方案1】:

    此问题的解决方案是使用自定义变量参数 (v:)。稍后可以通过设置 webhook 来捕获这些参数。在我的例子中,我的 webhook 中的 cupon-id POST 参数将包含 cupon 自定义变量的值。

    request.AddParameter("recipient-variables", vars.ToJSON());
    request.AddParameter("v:cupon-id", "{cupon:\"%recipient.cupon%\"}");
    request.AddParameter("o:tracking", true);
    

    请注意,这些自定义变量必须是 JSON 字符串 according to the documentation

    【讨论】:

    • 如何将客户邮件存储在“Dictionary vars”中,请给出示例代码。我的文本框中有电子邮件,我将这些电子邮件存储在列表中,但不知道如何传递接收变量
    • 你应该问一个新问题
    猜你喜欢
    • 1970-01-01
    • 2016-07-03
    • 2015-09-15
    • 2018-09-05
    • 2019-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多