Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SparkPost-未接收单击事件_Java_Sparkpost - Fatal编程技术网

Java SparkPost-未接收单击事件

Java SparkPost-未接收单击事件,java,sparkpost,Java,Sparkpost,因此,我有一个http端点,用于从SparkPost接收不同类型的事件(如传递、反弹、投诉、开放跟踪等)。一切正常,但我没有收到任何关于点击事件的帖子。以下是我到目前为止所做的尝试: private void sendEmail(String from, String[] recipients) throws SparkPostException { TransmissionWithRecipientArray transmission = new TransmissionWithRe

因此,我有一个http端点,用于从SparkPost接收不同类型的事件(如传递、反弹、投诉、开放跟踪等)。一切正常,但我没有收到任何关于点击事件的帖子。以下是我到目前为止所做的尝试:

 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);
}
private void sendmail(String from,String[]recipients)引发SparkPostException{
TransmissionWithRecipientArray传输=新传输WithRecipientArray();
ArrayList标记=新的ArrayList();
标记。添加(“标记1”);
标记。添加(“标记2”);
//填充收件人
List recipientArray=new ArrayList();
for(字符串收件人:收件人){
RecipientAttributes RecipientAttributes=新RecipientAttributes();
recipientAttribs.setAddress(新地址属性(收件人));
recipientAttribs.setTags(标签);
recipientArray.add(recipientAttribs);
}
传输.setRecipientArray(recipientArray);
//填充替换数据
Map substitutionData=newhashmap();
替换数据。放置(“链接”http://www.google.com?utm_campaign=test_campaign");
OptionsAttributes OptionsAttributes=新的OptionsAttributes();
optionsAttributes.setClickTracking(true);//这似乎没有什么区别
optionsAttributes.setOpenTracking(true);
传输.设置替换数据(替换数据);
传输设置选项(选项属性);
transmission.setCampaignId(“测试活动”);
映射元数据=新建HashMap();
元数据.put(“用户类型”、“测试”);
传输元数据(元数据);
传输。设置返回路径(“example@some-邮件(mail.com),;
//填充电子邮件正文
TemplateContentAttributes contentAttributes=新的TemplateContentAttributes();
setFrom(新地址属性(from));
setSubject(“此处为您的主题内容”);
setText(“此处的文本内容”);
setHtml(您的HTML内容在这里。{{link}

”; 传输.setContentAttributes(contentAttributes); 传输.setContentAttributes(contentAttributes); //发送电子邮件 RestConnection=newrestconnection(this.client,getEndPoint()); 响应=ResourceTransmissions.create(连接,0,传输); System.out.println(“传输响应:+响应”); }
为了让SparkPost模板引擎只个性化
http(s)?
URL,而不是像
mailto这样的东西:a@b.com
,方案(
http://
https://
)需要在模板中,而不是在替换数据中。下面是一个例子:

模板:

这是一个链接到!

替代数据:

substitutionData.put(“myurl”,“www.google.com?utm_campaign=test_campaign”);


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

为了使SparkPost模板引擎仅个性化
http(s)?
url,而不包装
mailto:a@b.com
,该方案(
http://
https://
)需要在模板中,而不是在替换数据中。以下是一个示例:

模板:

这是一个链接到!

替代数据:

substitutionData.put(“myurl”,“www.google.com?utm_campaign=test_campaign”);


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

Hey@peech:)你给自己发过这样的邮件吗?我想你的链接被转义了,因为你使用了双大括号。尝试使用三个大括号{{{link}}}来防止html转义。如果我直接将
放在
contentAttributes.setHtml()中,这也不起作用
,我收到一个点击事件。当从
替换数据中输入时,点击事件没有到达。在您收到的电子邮件中,域是否指向SparkPost点击跟踪服务器,即spgo.io,还是仍然是google.com?它仍然是google.com这实际上是一个操作顺序。当您个性化一个实体时重新链接,我们的模板引擎需要能够看到url方案,以确保它不会尝试链接包装
mailto:
链接,例如。我将在回答中提供更多详细信息。嘿@peech:)您是否向自己发送过其中一封电子邮件?我认为您的链接被转义了,因为您使用了双花括号。尝试三个花括号{{{link}}}以防止html转义。这也不起作用:/I如果我直接将
放在
contentAttributes.setHtml()中
,我收到一个点击事件。当从
替换数据中输入时,点击事件没有到达。在您收到的电子邮件中,域是否指向SparkPost点击跟踪服务器,即spgo.io,还是仍然是google.com?它仍然是google.com这实际上是一个操作顺序。当您个性化一个实体时重新链接,我们的模板引擎需要能够看到url方案,以确保它不会尝试将
mailto:
链接包装起来。例如,我会在回答中提供更多详细信息。谢谢,这是按预期进行的。不敢相信我自己没有想到这一点…谢谢,这是按预期进行的。不敢相信我没有想到我自己。。。