【发布时间】:2016-08-29 20:26:23
【问题描述】:
所以,我有一个 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);
}
【问题讨论】:
-
嘿@peech :) 您是否已将其中一封电子邮件发送给自己?我认为您的链接正在转义,因为您使用的是双花括号。尝试三重花括号 {{{ link }}} 以防止 html 转义。
-
这也不起作用:/ 如果我将
<a href="http://www.google.com">Google</a>直接放入contentAttributes.setHtml(),我会收到一个点击事件。从substitutionData放入时,点击事件未到达。 -
在您收到的电子邮件中,域是否指向 SparkPost 点击跟踪服务器,即 spgo.io,还是仍然是 google.com?
-
它仍然是 google.com
-
这实际上是一个操作顺序。例如,当您个性化整个链接时,我们的模板引擎需要能够查看 url 方案,以确保它不会尝试链接包装
mailto:链接。我会在答案中提供更多细节。