我的下面代码完美地将电子邮件作为附件发送,但问题是
1)有效负载正在复制到邮件正文。我希望邮件只作为附件发送,不希望在邮件的正文部分包含附件。
2)始终两次发送电子邮件。我已经将线程数计为1.不确定第二个事件的触发位置。
代码:
<mule xmlns:email="http://www.mulesoft.org/schema/mule/email" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:context="http://www.springframework.org/schema/context" xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd">
<spring:beans>
<context:property-placeholder location="accord.properties"/>
<spring:bean id="transmission" class="com.creativeworld.service.InvokeTransmission"/>
</spring:beans>
<quartz:connector name="ABCQuartz" validateConnections="true" doc:name="ABC Quartz">
<quartz:factory-property key="org.quartz.scheduler.instanceName" value="ABC_XYZKReport"/>
<quartz:factory-property key="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool"/>
<quartz:factory-property key="org.quartz.threadPool.threadCount" value="1"/>
<quartz:factory-property key="org.quartz.scheduler.rmi.proxy" value="false"/>
<quartz:factory-property key="org.quartz.scheduler.rmi.export" value="false"/>
</quartz:connector>
<smtp:connector name="ABCSMTP" validateConnections="true" doc:name="SMTP" subject="ABC_XYZK Report"/>
<flow name="flow1" doc:name="flow1" processingStrategy="synchronous">
<quartz:inbound-endpoint jobName="ABCQuartz" repeatInterval="180000" responseTimeout="10000" connector-ref="ABCQuartz" doc:name="ABC XYZK">
<quartz:event-generator-job groupName="creativeworld" jobGroupName="creativeworld">
<quartz:payload>Creative World Quartz Scheduler.</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<scripting:component doc:name="Python">
<scripting:script engine="jython" file="ABC_XYZK.py"/>
</scripting:component>
<set-session-variable variableName="outputfilepath" value="${OUTPUT_FILE}${FILE_NAME}-#[server.dateTime.format('${DATETIME_FORMAT}')]${FILE_TYPE}" doc:name="File Name" />
<set-payload value="${COMMAND_PATH}#[' ']${DB_NAME}${OUTPUT_FILE}${URL}" doc:name="Transmission Commands"/>
<set-payload value="#[message.payload]#[' -outputpath ']#[outputfilepath]" doc:name="Output Config"/>
<invoke object-ref="transmission" method="invoke" methodArgumentTypes="java.lang.String" methodArguments="#[payload]" name="transmissionAPI"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="smtp" doc:name="VM"/>
</flow>
<flow name="smtp" doc:name="smtp" processingStrategy="synchronous">
<vm:inbound-endpoint exchange-pattern="one-way" path="smtp" doc:name="VM"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[new File(sessionVars['outputfilepath']).text]]></scripting:script>
</scripting:component>
<set-attachment attachmentName="${FILE_NAME}-#[server.dateTime.format('${DATETIME_FORMAT}')]${FILE_TYPE}" value="#[payload]" contentType="text/plain" doc:name="ABC_XYZK Report"/>
<smtp:outbound-endpoint host="mailrelay.ad.corp.local" responseTimeout="10000" doc:name="SMTP" connector-ref="ABCSMTP" mimeType="text/plain" from="mymailid@mycompany.com" subject="ABC_XYZK" to="mymailid@mycompany.com">
<!-- <email:email-to-string-transformer/> -->
</smtp:outbound-endpoint>
</flow>
答案 0 :(得分:2)
简单的解决方案: - 如果您不想在邮件正文中使用相同的有效负载,只需将<set-payload value="Hi this is the mail content " doc:name="Output Config"/>
放在<set-attachment >
标记之后,并将您希望拥有的内容作为邮件正文,例如: -
<set-attachment attachmentName="${FILE_NAME}-#[server.dateTime.format('${DATETIME_FORMAT}')]${FILE_TYPE}" value="#[payload]" contentType="text/plain" doc:name="ABC_XYZK Report"/>
<set-payload value="Hi this is the mail content " doc:name="Output Config"/>
<smtp:outbound-endpoint host="mailrelay.ad.corp.local" responseTimeout="10000" doc:name="SMTP" connector-ref="ABCSMTP" mimeType="text/plain" from="mymailid@mycompany.com" subject="ABC_XYZK" to="mymailid@mycompany.com">
<!-- <email:email-to-string-transformer/> -->
</smtp:outbound-endpoint>
您在附件后设置的有效负载将在您的邮件正文中