SparkPost-未接收Click事件



因此,我有一个http端点,用于接收来自SparkPost的不同类型的事件(如Delivery、Bounce、Complaint、Open Track…)。一切都很好,但我没有收到任何关于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)? URL,而不包装像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不会包装裸露的链接。

相关内容

  • 没有找到相关文章

最新更新