您的位置:首页 > 其它

调用webpowerAPI实现邮件发送功能(系统邮件一对一发送)

2013-12-31 16:10 966 查看
package com.cc.test;

import java.util.ArrayList;
import java.util.List;
import com.cc.webpower.DMdeliverySoapAPIClient;
import com.cc.webpower.DMdeliverySoapAPIPort;
import com.dmdelivery.webservice.AddRecipientsResultType;
import com.dmdelivery.webservice.ArrayOfIntType;
import com.dmdelivery.webservice.DMdeliveryLoginType;
import com.dmdelivery.webservice.NewGroupType;
import com.dmdelivery.webservice.NewRecipientType;
import com.dmdelivery.webservice.RecipientNameValuePairType;
import com.dmdelivery.webservice.RecordResultType;

public class Test {
public static void main(String[] args) {
DMdeliverySoapAPIClient  client = new DMdeliverySoapAPIClient();
try {

DMdeliverySoapAPIPort service = client.getDMdeliverySoapAPIPort();
DMdeliveryLoginType login = new DMdeliveryLoginType();
login.setUsername("liuxiaoyong");
login.setPassword("");
int campaignId=4;//活动ID(平台里面需要新建一个活动) 4:代表系统邮件
RecordResultType result ;
AddRecipientsResultType aresult;
int groupId;
int mailingId = 56; //在平台的邮件的邮件下面新建邮件
int recipientId;
//组可以自己定义,也可以在平台里面新建
NewGroupType group = new NewGroupType();
group.setName("Sample group");
group.setIsTest(true);
group.setRemarks("This group is added by an example");
result = service.addGroup(login, campaignId, group);
System.out.println("============"+result.getStatus());
if (result.getStatus().equals("ERROR")) {
throw new RuntimeException("Error creating group " +
result.getStatusMsg());
}else{
groupId = result.getId();
}
///
System.out.println(groupId);
ArrayOfIntType groupIDs= new ArrayOfIntType();
groupIDs.getInt().add(groupId);//组ID
//定义收件人邮件标题和内容
NewRecipientType recipientData=new NewRecipientType();
//RecipientNameValuePairType fields=new RecipientNameValuePairType();
//fields.setName("email");
//fields.setValue("liuxiaoyong23@163.com");
//NewRecipientArrayType recipientDatas = new NewRecipientArrayType();
//收件人地址
RecipientNameValuePairType fields=new RecipientNameValuePairType();
fields.setName("email");
fields.setValue("liuxiaoyong23@163.com");
//邮件标题
RecipientNameValuePairType fieldssubject=new RecipientNameValuePairType();
fieldssubject.setName("subject");//在webpower平台里面新建的个性化(需要在平台里面新建subject字段)
fieldssubject.setValue("邮件测试2013-12-28");
//邮件内容
RecipientNameValuePairType fieldscontent=new RecipientNameValuePairType();
fieldscontent.setName("content");//在webpower平台里面新建的个性化(需要在平台里面新建content字段)
fieldscontent.setValue("邮件测试2013-12-28 内容");
List<RecipientNameValuePairType> list = new ArrayList<RecipientNameValuePairType>();
list.add(fields);
list.add(fieldssubject);
list.add(fieldscontent);
recipientData.getFields().addAll(list);
boolean addDuplisToGroups = true;
boolean overwrite = true;
result=service.addRecipient(login, campaignId, groupIDs, recipientData, addDuplisToGroups, overwrite);
//aresult=service.addRecipients(login, campaignId, groupIDs, recipientDatas, addDuplisToGroups, overwrite);

if (result.getStatus().equals("ERROR")){
System.out.println("msg===="+result.getStatusMsg());
throw new RuntimeException("创建邮件错误" +
result.getStatusMsg());

}else{
recipientId = result.getId();
}
//Send single mailing
System.out.println("recipientId===="+recipientId);
Boolean flg;
flg = service.sendSingleMailing(login, campaignId, mailingId, recipientId);
if(flg == false){
throw new RuntimeException("Error send single mailing.");
}
System.out.println("成功");

} catch (Exception e) {
System.out.println("失败");
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: