Activiti5邮件发送失败:无法添加接收人邮箱地址
org.activiti.engine.ActivitiException: Could not add ${toEmail} as recipient
Caused by: org.apache.commons.mail.EmailException: javax.mail.internet.AddressException: Missing final ‘@domain’ in string ``${toEmail}’’
这个错误是做众筹项目以来困住我比较久的bug了,花了半天时间才解决。网上有一些人也遇到这个情况,但几乎都没有答案,有回答也是摸棱两可,鸡同鸭讲。缺乏度娘的帮助,只能自己慢慢想了,当直接在流程图填写邮箱地址时,邮件是可以正常发送的,那么配置环境什么的应该是没有问题的,那么只有这个${toEmail}参数接收问题了。于是便去查看activiti5的用户手册。
当看到案例的邮件任务的xml文件时,如下:
<serviceTask id="sendMail" activiti:type="mail">
<extensionElements>
<activiti:field name="from" stringValue="order-shipping@thecompany.com" />
<activiti:field name="to" expression="${recipient}" />
<activiti:field name="subject" expression="Your order ${orderId} has been shipped" />
<activiti:field name="html">
<activiti:expression>
<![CDATA[
<html>
<body>
Hello ${male ? 'Mr.' : 'Mrs.' } ${recipientName},<br/><br/>
As of ${now}, your order has been <b>processed and shipped</b>.<br/><br/>
Kind regards,<br/>
TheCompany.
</body>
</html>
]]>
</activiti:expression>
</activiti:field>
</extensionElements>
</serviceTask>
而当我们同时也用xml格式打开查看流程文件时(部分内容),
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1596164063243" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
<process id="authProcess" isClosed="false" isExecutable="true" processType="None">
<startEvent id="authProcess_2" name="StartEvent"/>
<serviceTask activiti:exclusive="true" activiti:type="mail" id="authProcess_3" name="发送验证码">
<extensionElements>
<activiti:field name="to">
<activiti:string>${toEmail}</activiti:string>
</activiti:field>
<activiti:field name="from">
<activiti:string>hanhan@bin.com</activiti:string>
</activiti:field>
<activiti:field name="subject">
<activiti:string>实名审核验证码</activiti:string>
</activiti:field>
<activiti:field name="charset">
<activiti:string>UTF-8</activiti:string>
</activiti:field>
<activiti:field name="html">
<activiti:string>验证码:${authcode}</activiti:string>
</activiti:field>
</extensionElements>
</serviceTask>
```xml
在这里插入代码片
对比就可知道
<activiti:string>${toEmail}</activiti:string>
这个出现了问题,idea把流程图解析成xml文件时将其当作字符串String了,所以这个“字符串”${toEmail}是非法的邮箱格式,当然也不能接收参数了。
解决:
修改如下(整个文件):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1596164063243" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
<process id="authProcess" isClosed="false" isExecutable="true" processType="None">
<startEvent id="authProcess_2" name="StartEvent"/>
<serviceTask activiti:exclusive="true" activiti:type="mail" id="authProcess_3" name="发送验证码">
<extensionElements>
<activiti:field name="to">
<activiti:expression>${toEmail}</activiti:expression>
</activiti:field>
<activiti:field name="from">
<activiti:string>hanhan@bin.com</activiti:string>
</activiti:field>
<activiti:field name="subject">
<activiti:string>实名审核验证码</activiti:string>
</activiti:field>
<activiti:field name="charset">
<activiti:string>UTF-8</activiti:string>
</activiti:field>
<activiti:field name="html">
<activiti:expression>验证码:${authcode}</activiti:expression>
</activiti:field>
</extensionElements>
</serviceTask>
<userTask activiti:assignee="${loginacct}" activiti:exclusive="true" id="authProcess_4" name="验证码审核"/>
<userTask activiti:candidateGroups="assignUsers" activiti:exclusive="true" id="authProcess_5" name="后台审核"/>
<exclusiveGateway gatewayDirection="Unspecified" id="authProcess_6" name="ExclusiveGateway"/>
<endEvent id="_7" name="EndEvent"/>
<endEvent id="_8" name="EndEvent"/>
<sequenceFlow id="_9" sourceRef="authProcess_2" targetRef="authProcess_3"/>
<sequenceFlow id="_10" sourceRef="authProcess_3" targetRef="authProcess_4"/>
<sequenceFlow id="_11" sourceRef="authProcess_4" targetRef="authProcess_5"/>
<sequenceFlow id="_12" sourceRef="authProcess_5" targetRef="authProcess_6"/>
<sequenceFlow id="_13" name="审核通过" sourceRef="authProcess_6" targetRef="_7">
<extensionElements>
<activiti:executionListener delegateExpression="${passListener}" event="end"/>
</extensionElements>
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[${flag==true}]]>
</conditionExpression>
</sequenceFlow>
<sequenceFlow id="_14" name="审核拒绝" sourceRef="authProcess_6" targetRef="_8">
<extensionElements>
<activiti:executionListener delegateExpression="${refuseListener}" event="end"/>
</extensionElements>
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[${flag==false}]]>
</conditionExpression>
</sequenceFlow>
</process>
<bpmndi:BPMNDiagram documentation="background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
<bpmndi:BPMNPlane bpmnElement="authProcess">
<bpmndi:BPMNShape bpmnElement="authProcess_2" id="Shape-authProcess_2">
<omgdc:Bounds height="32.0" width="32.0" x="155.0" y="15.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="authProcess_3" id="Shape-authProcess_3">
<omgdc:Bounds height="55.0" width="85.0" x="130.0" y="130.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="authProcess_4" id="Shape-authProcess_4">
<omgdc:Bounds height="55.0" width="85.0" x="130.0" y="260.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="authProcess_5" id="Shape-authProcess_5">
<omgdc:Bounds height="55.0" width="85.0" x="130.0" y="385.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="authProcess_6" id="Shape-authProcess_6" isMarkerVisible="false">
<omgdc:Bounds height="32.0" width="32.0" x="305.0" y="340.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7">
<omgdc:Bounds height="32.0" width="32.0" x="450.0" y="340.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_8" id="Shape-_8">
<omgdc:Bounds height="32.0" width="32.0" x="450.0" y="460.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13" sourceElement="_6" targetElement="_7">
<omgdi:waypoint x="337.0" y="356.0"/>
<omgdi:waypoint x="450.0" y="356.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12" sourceElement="_5" targetElement="_6">
<omgdi:waypoint x="215.0" y="412.5"/>
<omgdi:waypoint x="305.0" y="356.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_14" id="BPMNEdge__14" sourceElement="_6" targetElement="_8">
<omgdi:waypoint x="320.0" y="371.0"/>
<omgdi:waypoint x="320.0" y="430.0"/>
<omgdi:waypoint x="450.0" y="476.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="43.0" x="0.0" y="-4.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_9" id="BPMNEdge__9" sourceElement="_2" targetElement="_3">
<omgdi:waypoint x="171.0" y="47.0"/>
<omgdi:waypoint x="171.0" y="130.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_11" id="BPMNEdge__11" sourceElement="_4" targetElement="_5">
<omgdi:waypoint x="172.5" y="315.0"/>
<omgdi:waypoint x="172.5" y="385.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10" sourceElement="_3" targetElement="_4">
<omgdi:waypoint x="172.5" y="185.0"/>
<omgdi:waypoint x="172.5" y="260.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
修改完后,问题也解决了。这个锅idea要稳稳背上了,不过听说idea在2014年就已经不再更新actviti插件了,也难怪也出现这样的错误。