Sending email with multiple attachment is not working in mule ESB using set-attachment -
<flow name="sendmailflow" > <http:listener config-ref="http_listener_configuration" path="${sendmail.path}" doc:name="http"/> <!-- http:inbound-endpoint exchange-pattern="request-response" host="${sendmail.host}" port="${sendmail.port}" path="${sendmail.path}" doc:name="http" /--> <logger message="logging #[payload]" level="info" doc:name="logger" /> <json:json-to-object-transformer returnclass="com.rsa.esbcommons.mailsender.maildata" doc:name="json object" /> <foreach collection="#[payload.getattachments()]" doc:name="for each attachment in maildata"> <set-attachment attachmentname="#[payload.getfilename()]" value="#[payload.getbase64attachmentcontent()]" contenttype="#[payload.getcontenttype()]" doc:name="create attachment" /> </foreach> <smtp:outbound-endpoint user="${smtp.user}" password="${smtp.password}" host="${smtp.host}" from="${smtp.from}" responsetimeout="10000" doc:name="smtp" mimetype="text/html" transformer-refs="maildatatoemailtransformer stringtoemail" /> <custom-transformer class="com.rsa.esbcommons.mailsender.mailresponsemessagetransformer" doc:name="mailresponsetransformer"/> <json:object-to-json-transformer sourceclass="com.rsa.esbcommons.mailsender.baseresponse" doc:name="sendmail response json"/> </flow> here issue attachment fails when set-attachment used in foreach loop given above. sending multiple attachment email. can use set-attachment in foreach loop?please in advance
this post old expose solution have same problem.
the problem here after foreach sentence, mule message recovering original state (empty outboundattachments). must create temporary flow var, , overwrite in each iteration current message.outboundattachments. finally, outside each scope, must set message.outboundattachments copying temporary var. here code should try.
<flow name="sendmailflow" > <http:listener config-ref="http_listener_configuration" path="${sendmail.path}" doc:name="http"/> <json:json-to-object-transformer returnclass="com.rsa.esbcommons.mailsender.maildata" doc:name="json object" /> <set-variable variablename="attaches" value="#[new java.util.hashmap()]" /> <foreach collection="#[payload.getattachments()]" doc:name="for each attachment in maildata"> <set-attachment attachmentname="#[payload.getfilename()]" value="#[payload.getbase64attachmentcontent()]" contenttype="#[payload.getcontenttype()]" doc:name="create attachment" /> <expression-component><![cdata[java.util.set keys = message.outboundattachments.keyset(); for(object key:keys){flowvars.attaches.put(key, message.outboundattachments.get(key)); }]]> </expression-component> </foreach> <expression-component> <![cdata[ message.outboundattachments.putall(flowvars.attaches); ]]> </expression-component> <smtp:outbound-endpoint user="${smtp.user}" password="${smtp.password}" host="${smtp.host}" from="${smtp.from}" responsetimeout="10000" doc:name="smtp" mimetype="text/html" transformer-refs="maildatatoemailtransformer stringtoemail" /> <custom-transformer class="com.rsa.esbcommons.mailsender.mailresponsemessagetransformer" doc:name="mailresponsetransformer"/> <json:object-to-json-transformer sourceclass="com.rsa.esbcommons.mailsender.baseresponse" doc:name="sendmail response json"/> </flow>` and i'm not sure if should delete string email transformer ref. worked me.
Comments
Post a Comment