SparkPost - 没有收到点击事件

SparkPost - not receiving Click Events

所以,我有一个 http 端点,用于从 SparkPost 接收不同类型的事件(例如投递、退回、投诉、打开跟踪等)。一切正常,但我没有收到有关 Click 事件的任何帖子。这是我到目前为止尝试过的方法:

 private void sendEmail(String from, String[] recipients) throws SparkPostException {
    TransmissionWithRecipientArray transmission = new TransmissionWithRecipientArray();

    ArrayList<String> tags = new ArrayList<String>();
    tags.add("tag #1");
    tags.add("tag #2");
    // Populate Recipients
    List<RecipientAttributes> recipientArray = new ArrayList<RecipientAttributes>();
    for (String recipient : recipients) {
        RecipientAttributes recipientAttribs = new RecipientAttributes();
        recipientAttribs.setAddress(new AddressAttributes(recipient));
        recipientAttribs.setTags(tags);
        recipientArray.add(recipientAttribs);
    }
    transmission.setRecipientArray(recipientArray);

    // Populate Substitution Data
    Map<String, Object> substitutionData = new HashMap<String, Object>();
    substitutionData.put("link", "http://www.google.com?utm_campaign=test_campaign");


    OptionsAttributes optionsAttributes = new OptionsAttributes();
    optionsAttributes.setClickTracking(true); // THIS DOESN'T SEEM TO MAKE A DIFFERENCE
    optionsAttributes.setOpenTracking(true);


    transmission.setSubstitutionData(substitutionData);
    transmission.setOptions(optionsAttributes);
    transmission.setCampaignId("test_campaign");

    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("user_type", "test");
    transmission.setMetadata(metadata);
    transmission.setReturnPath("example@some-mail.com");
    // Populate Email Body
    TemplateContentAttributes contentAttributes = new TemplateContentAttributes();
    contentAttributes.setFrom(new AddressAttributes(from));
    contentAttributes.setSubject("Your subject content here.");
    contentAttributes.setText("Your Text content here.");

    contentAttributes.setHtml("<p>Your <b>HTML</b> content here. {{ link }}</p>");

    transmission.setContentAttributes(contentAttributes);

    transmission.setContentAttributes(contentAttributes);

    // Send the Email
    RestConnection connection = new RestConnection(this.client, getEndPoint());
    Response response = ResourceTransmissions.create(connection, 0, transmission);

    System.out.println("Transmission Response: " + response);
}

为了让 SparkPost 模板引擎只个性化 http(s)? urls,而不是包装像 mailto:a@b.com 这样的东西,方案(http://https://) 需要在模板中,而不是在替换数据中。这是一个例子:

模板: This is a link to <a href="http://{{{myurl}}}">somewhere awesome</a>!

换人数据: substitutionData.put("myurl", "www.google.com?utm_campaign=test_campaign");

这里实际上有三个变化 - 第二个是使用三重 curlies {{{ 而不是 {{ 双 curlies,以避免 html-转义替换变量的内容。第三个是将 url 放在锚标记内,因为 SparkPost 不会包装裸链接。