1.查询联系人列表
/**
* 第一步:根据联系人列表名,查询联系人列表
* @return 列表ID
* @throws Exception
*/
public Integer queryContactListId(ApiClient apiClientExp, String listName) throws Exception {
ConcurrentHashMap map = new ConcurrentHashMap();
map.put("q", listName);
map.put("start-index", "1");
map.put("max-results", "1");
Feed feed = apiClientExp.queryContactList(map);
XmlUtil.displayEncodeXml(feed);
if (feed != null) {
List list = feed.getEntries();
if (list != null && list.size() > 0) {
Entry entry = list.get(0);
String path = entry.getId().getPath();
return getIdByPath(path);
}
}
return null;
}
2.查询邮件
/**
* 第二步:根据标题查询邮件
* 查询邮件ID
* @param apiClientExp
* @param title 邮件标题
* @return
* @throws Exception
*/
public Integer queryMailId(ApiClient apiClientExp,String title) throws Exception {
ConcurrentHashMap queryMap = new ConcurrentHashMap();
queryMap.put("q",title);
queryMap.put("start-index","1");
queryMap.put("max-results","10");
Feed feed = apiClientExp.queryMailList(queryMap);
if (feed != null) {
List list = feed.getEntries();
if (list != null && list.size() > 0) {
Entry entry = list.get(0);
return getIdByPath(entry.getId().getPath());
}
}
return null;
}
3.创建发送任务|系统邮件
/**
* 第三步: 创建发送任务
*
* @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("技术小组测试"); //发送任务Title
entry.addExtension(AtomConstants.QName_UM_SUBJECT).setText("五一放假通知"); //邮件主题
/**
* 注册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());
}
示例2 下载(CompositiveTest2.java)