Question

My below code perfectly send email as an attachment, but the problem is

1) payload is copying to the mail body. I want mail to be sent only as an attachment, don't want to include attachment in body part of the mail.

2) email triggers twice always. I have given thread count as 1. Not sure from where the second event is triggering.

Code:

<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>
Was it helpful?

Solution

Simple solution :- If you don't want the same payload in the mail body simply put <set-payload value="Hi this is the mail content " doc:name="Output Config"/> just after <set-attachment > tag with the content you like to have as mail body eg :-

<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>

The payload you set after attachment will be in your mail body

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top