示例1
目录 |
第一步:创建联系人列表
/** * 第一步:创建联系人列表(如果不需要创建,可以查询) * @return 列表ID * @throws Exception */ public Integer createContactList(ApiClient apiClientExp) throws Exception { Abdera abdera = Abdera.getInstance(); Entry entry = abdera.newEntry(); entry.addSimpleExtension(AtomConstants.TITLE,"技术组"); entry.addSimpleExtension(AtomConstants.SUBTITLE,"研发小组"); entry.addExtension(AtomConstants.QName_UM_ATTRIBUTE) .setAttributeValue("name", "Birthday") .setAttributeValue("label","生日") .setAttributeValue("visible", "true") .setAttributeValue("public","true") .setAttributeValue("sn", "1") .setAttributeValue("type","text"); entry.addExtension(AtomConstants.QName_UM_ATTRIBUTE) .setAttributeValue("name", "city") .setAttributeValue("label","所在城市") .setAttributeValue("visible", "false") .setAttributeValue("public","false") .setAttributeValue("sn", "2") .setAttributeValue("type","text"); entry.addExtension(AtomConstants.QName_UM_ATTRIBUTE) .setAttributeValue("name", "phoneA") .setAttributeValue("label","我的电话") .setAttributeValue("visible", "true") .setAttributeValue("public","true") .setAttributeValue("sn", "3") .setAttributeValue("type","text"); Entry res = apiClientExp.createContactList(entry); String path = res.getId().getPath(); return getIdByPath(path); }
第二步:添加联系人
/** * 第二步:向联系人列表中添加联系人 * @param apiClientExp * @param listId 联系人列表ID * @return * @throws Exception */ public Integer addContacts(ApiClient apiClientExp,Integer listId) throws Exception { Abdera abdera = Abdera.getInstance(); Feed feed = abdera.newFeed(); Entry contact1 = feed.addEntry(); contact1.addExtension(AtomConstants.EMAIL).setText("unimail2012@163.com"); contact1.addExtension(AtomConstants.TITLE).setText("liudejian"); contact1.addExtension(AtomConstants.QName_UM_TYPE).setText("html"); contact1.addExtension(AtomConstants.QName_UM_STATUS).setText("activity"); contact1.addExtension(AtomConstants.QName_UM_ATTRIBUTE).setAttributeValue("name", "phoneA").setText("010-88886666"); contact1.addExtension(AtomConstants.QName_UM_ATTRIBUTE).setAttributeValue("name", "birthday").setText("1983-02-06"); contact1.addExtension(AtomConstants.QName_UM_ATTRIBUTE).setAttributeValue("name", "city").setText("北京上帝"); contact1.addLink("http://services.unimarketing.com.cn/list/"+listId).setRel("related"); Entry contact2 = feed.addEntry(); contact2.addExtension(AtomConstants.EMAIL).setText("unimail2011@163.com"); contact2.addExtension(AtomConstants.TITLE).setText("dj"); contact2.addExtension(AtomConstants.QName_UM_TYPE).setText("html"); contact2.addExtension(AtomConstants.QName_UM_STATUS).setText("activity"); contact2.addExtension(AtomConstants.QName_UM_ATTRIBUTE).setAttributeValue("name", "phoneA").setText("010-88866699"); contact2.addExtension(AtomConstants.QName_UM_ATTRIBUTE).setAttributeValue("name", "birthday").setText("1983-06-08"); contact2.addExtension(AtomConstants.QName_UM_ATTRIBUTE).setAttributeValue("name", "city").setText("北京上帝"); contact2.addLink("http://services.unimarketing.com.cn/list/"+listId).setRel("related"); XmlUtil.displayEncodeXml(feed); Feed res = apiClientExp.addContacts(feed); XmlUtil.displayEncodeXml(res); return listId; }
第三步:创建邮件分类
/** * 第三步:创建邮件分类 * @return 分类ID * @throws Exception */ public Integer createMailClassify(ApiClient apiClientExp) throws Exception { Abdera abdera = Abdera.getInstance(); Entry entry = abdera.newEntry(); /** * 表示在 我的邮件 分类下建立 技术测试 子分类 */ entry.addSimpleExtension(AtomConstants.TITLE, "技术测试"); entry.addLink("http://services.unimarketing.com.cn/folder/我的邮件") .setAttributeValue("rel", "related"); Entry res = apiClientExp.createMailClassify(entry); String path = res.getId().getPath(); // XmlUtil.displayEncodeXml(res); return getIdByPath(path); }
第四步:创建邮件
/** * 第四步:创建邮件 * @return 邮件ID * @throws Exception */ public Integer createMail(ApiClient apiClientExp) throws Exception { Abdera abdera = Abdera.getInstance(); Entry entry = abdera.newEntry(); entry.addSimpleExtension(AtomConstants.TITLE, "技术小组邮件通知"); entry.addLink("http://services.unimarketing.com.cn/folder/我的邮件/技术测试").setAttributeValue("rel", "related"); entry.addExtension(AtomConstants.QName_UM_HEADERALIGN).setAttributeValue("align","center"); entry.addExtension(AtomConstants.QName_UM_FOOTERALIGN).setAttributeValue("align","center"); entry.addExtension(AtomConstants.QName_UM_LANGUAGE).setText("zh_CN"); entry.setContent(""+ ""+ ""+ " "+ " "+ "此邮件发送至 [$contact.email ] ,您收到此邮件是因为您向 “杨洋阳” 提供了您的邮件地址。
\"杨洋阳\" 尊重您的隐私。若要更新您的信息,请点击 用户中心 ;如果您不希望再次收到 “杨洋阳” 发来的电子邮件,请点击 退订 取消订阅;若您对此邮件内容感兴趣,也可点击 推荐给好友将邮件推荐给您的好友一同分享。"+ ""+ ""+ " ]]>") .setAttributeValue("type", "html") .setAttributeValue("xml:base", "http://unimarketing.com.cn/"); Entry res = apiClientExp.createMail(entry); XmlUtil.displayEncodeXml(res); String path = res.getId().getPath(); return getIdByPath(path); }
退订 | 投诉
第五步:创建发送任务
/** * 第五步: 创建发送任务 * @param apiClientExp * @param messageId 邮件ID * @param contactList 联系人列表 * @return 任务ID * @throws Exception */ public Integer createSendTask(ApiClient apiClientExp,Integer messageId, Integer [] contactList) throws Exception { Abdera abdera = Abdera.getInstance(); Entry entry = abdera.newEntry(); entry.addExtension(AtomConstants.TITLE).setText("技术小组测试"); entry.addExtension(AtomConstants.QName_UM_SUBJECT).setText("wish success!"); /** * 注册from 地址必需与公司注册的mail_from地址一样 */ entry.addExtension(AtomConstants.QName_UM_FROM).setText("DJ"); entry.addExtension(AtomConstants.QName_UM_REPLY).setText("unimail2011@163.com"); entry.addExtension(AtomConstants.QName_UM_TRIGGERMETHOD).setText("time"); // entry.addExtension(AtomConstants.QName_UM_TRIGGERCONDITION).setText("immediately"); //立即发送,如果是立即发送就不需要发送时间 entry.addExtension(AtomConstants.QName_UM_STARTUPTIME).setText("2011-04-28 13:14:24"); entry.addExtension(AtomConstants.QNAME_UM_OPTIMIZEPOLICY).setText("auto"); entry.addExtension(AtomConstants.QName_UM_ANALYTICSPOLICY).setText("GA(OnlyGenerateTrackingURLs)"); entry.addExtension(AtomConstants.QName_UM_DOMAINSCOPE).setText("http://beijing.piaowu.com.cn"); entry.addExtension(AtomConstants.QName_UM_DOMAINSCOPE).setText("http://tianjing.piaowu.com.cn"); /** * 需要发送的邮件 */ entry.addLink("http://services.unimarketing.com.cn/message/"+messageId).setAttributeValue("rel", "related"); for (Integer listId : contactList) { entry.addLink("http://services.unimarketing.com.cn/list/"+listId).setAttributeValue("rel", "related"); } // entry.addExtension(AtomConstants.QNAME_UM_SENDTYPE).setText("system"); //系统邮件,不会有跟踪。 也不会有报表 entry.addExtension(AtomConstants.QNAME_UM_SENDTYPE).setText("normal"); //计划邮件 /** * 如果 是系统邮件这个Email就是系统邮件收件人地址 */ entry.addLink("http://www.unimarketing.com.cn/contact/unimail2012@163.com").setAttributeValue("rel", "alternate"); Entry res = apiClientExp.createSendTask(entry); XmlUtil.displayEncodeXml(res); System.out.println("start-sendTime:"+res.getSimpleExtension(AtomConstants.QName_UM_STARTUPTIME)); return getIdByPath(res.getId().getPath()); }
第六步:根据发送计划ID,取得报表数据
/** * 第六步:获取单个发送任务报表数据 * * @return 报表数据 * @throws Exception */ public Entry getSigleReport(ApiClient apiClientExp,Long scheduleId) throws Exception { return apiClientExp.querySingleSendTaskInfo(scheduleId.toString()); }