JBPM的邮件发送实例

用MDeamon作为本地的邮件服务器,发送邮件测试

mySendEmail.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>

<process name="mySendEmail" xmlns="http://jbpm.org/4.4/jpdl">
	<start g="57,45,48,48" name="start1">
		<transition g="-57,-27" name="to send rectify note" to="发信" />
	</start>
	<mail g="281,50,115,45" language="juel" name="发信">
		<to addresses="[email protected]" />
		<cc groups="innerparty" users="#{cc_user}" />
		<bcc groups="thinkpol" />
		<subject>rectify ${newspaper}</subject>
		<text>${newspaper} ${date} reporting bb dayorder doubleplusungood
			refs unpersons 中文信件 fullwise upsub antefiling</text>
		<attachments>
			<attachment url='http://www.george-orwell.org/1984/3.html' />
			<attachment resource='test.html' />
			<attachment file='d:\\AppConfig.xml' />
 		</attachments>
	</mail>
</process>

 
public class SendMailMain {
	// protected static String deploymentId;
	protected static ProcessEngine		processEngine				= null;
	protected static RepositoryService	repositoryService			= null;
	protected static ExecutionService	executionService;
	protected static ManagementService	managementService;
	protected static TaskService		taskService;
	protected static HistoryService		historyService;
	protected static IdentityService	identityService;

	public ProcessInstance				processInstance				= null;
 
	private static String				processDefinitionKey		= "mySendEmail";
	private static String				processDefinitionVersion	= "1";
	private static String				processDefinitionId			= processDefinitionKey + "-" + processDefinitionVersion;
	private static Map<String, String>	processSessionParams		= new HashMap<String, String>();

	/**
	 * 以请假流程为例,进行工作流实例
	 * 
	 * @param args
	 */
	public static void main(String[] args) {

		SendMailMain demo = new SendMailMain();

		// 1 初始化工作流环境
		initialize();

		// 2 部署工作流
		demo.deployProcess(true, "mySendEmail.jpdl.xml");

		// 3 预设流程参数
		demo.preDef4Process();

		// 4 工作流定义实例化
		demo.startProcess(processDefinitionKey, processSessionParams);
	}

	/**
	 * 初始化流程引擎
	 */
	protected static synchronized void initialize() {
		if (processEngine == null) {
			processEngine = Configuration.getProcessEngine();

			repositoryService = processEngine.get(RepositoryService.class);
			executionService = processEngine.getExecutionService();
			historyService = processEngine.getHistoryService();
			managementService = processEngine.getManagementService();
			taskService = processEngine.getTaskService();
			identityService = processEngine.getIdentityService();
		}
	}

	/**
	 * 部署流程文件
	 * 
	 * @param isRebulid
	 *            是否重建流程定义
	 * @param pdlFile
	 */
	public void deployProcess(boolean isRebulid, String pdlFile) {
		URL url = this.getClass().getResource(pdlFile);
		if (url == null) {
			System.err.println("未找到流程定义文件【" + pdlFile + "】");

		} else {
			if (isRebulid) {
				// 首次建立流程时获取流程ID,以便以后重复使用
				repositoryService.createDeployment().addResourceFromUrl(url).deploy();
			} else {
				// 重用流程: 使用processDefinitionId初始化repositoryService
				repositoryService.getStartActivityNames(processDefinitionId);
			}
		}
	}

	/**
	 * 由流程定义生成流程实例,保存在processInstance 变量中。
	 * 
	 * @param pdKey
	 *            流程定义标识
	 * @param envParams
	 *            流程启动参数
	 */
	protected void startProcess(String pdKey, Map<String, ?> envParams) {
		// 待环境参数,启动流程实例:启动对指定流程图的升级
		processInstance = executionService.startProcessInstanceByKey(pdKey, envParams);
	}

	/**
	 * 预设流程中将使用的参数
	 */
	public void preDef4Process() {
		// 创建jbpm用户
		identityService.createUser("qian", "钱", null, "[email protected]");
		identityService.createUser("zhu", null, "朱", "[email protected]");
		identityService.createUser("wang", null, "王", "[email protected]");
		identityService.createGroup("thinkpol");
		identityService.createGroup("innerparty");
		identityService.createMembership("qian", "innerparty");
		identityService.createMembership("zhu", "thinkpol");
		identityService.createMembership("wang", "thinkpol");

		// ----------- 启动流程前的会话参数准备 -------------
		// cc_user 变量填入参数
		processSessionParams.put("cc_user", "qian");
		processSessionParams.put("newspaper", "newspap新闻er111");
		processSessionParams.put("date", "2010-2-2");

	}

}



----- 关键步骤 ----
在MDeamon中需要设置RFC不检查,否则将出现如下错误
15:39:32,046 INF | [DefaultCommandService] exception while executing command org.jbpm.pvm.internal.cmd.StartProcessInstanceInLatestCmd@196bac4
org.jbpm.api.JbpmException: could not send email: javax.mail.internet.MimeMessage@15d8d75
at org.jbpm.pvm.internal.email.impl.MailSessionImpl.send(MailSessionImpl.java:60)
at org.jbpm.jpdl.internal.activity.MailActivity.perform(MailActivity.java:46)

Caused by: com.sun.mail.smtp.SMTPSendFailedException: 554 Message is not RFC compliant
导致邮件发送失败
MDeamon→菜单→设置(S)→默认域/服务器→服务器 
checbox:拒绝不符合RFC的邮件 (不选择此功能)

你可能感兴趣的:(xml,工作,jbpm,sun)