[mule-user] IMAP/POP3 Save Attachment from Email

973 views
Skip to first unread message

Vladimir Baranov

unread,
Sep 24, 2010, 4:55:13 PM9/24/10
to us...@mule.codehaus.org
Hi,

I was wondering if anyone was able to figure out this one yet.

steps:
1. Grab email from IMAP/POP3 box
2. Transform to a set of attachments
3. Save attachments in a specific folder based on email subject or attachment name


here what I have come up with, however it's not working yet. I was able to save the text of the email as text (set transformer-refs of imap to "EmailToByteMessage"), but saving the attachments did not work. Am I on the right path?


<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:imap="http://www.mulesoft.org/schema/mule/imap"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:email="http://www.mulesoft.org/schema/mule/email"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.0/mule.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/3.0/mule-email.xsd
http://www.mulesoft.org/schema/mule/imap http://www.mulesoft.org/schema/mule/imap/3.0/mule-imap.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/3.0/mule-file.xsd">

<imap:connector name="imapConnector" backupEnabled="true" backupFolder="newBackup" checkFrequency="5000" mailboxFolder="INBOX" deleteReadMessages="true"/>
<file:connector name="receiveConnector" fileAge="500" autoDelete="true" pollingFrequency="100"/>
<email:mime-to-bytes-transformer name="EmailToByteMessage"/>
<expression-transformer name="getAttachment0">
<return-argument evaluator="attachment" expression="0"/>
</expression-transformer>

<model>
<service name="ServiceSaveEmailToFile">
<description>Save email to File</description>
<inbound>
<imap:inbound-endpoint user="$USER" port="$PORT" password="$PASSWORD" host="$HOST" disableTransportTransformer="true" transformer-refs="EmailToByteMessage getAttachment0"/>
</inbound>
<outbound>
<pass-through-router>
<file:outbound-endpoint path="./test" outputPattern="last_${DATE}_email.txt" />
</pass-through-router>
</outbound>
</service>
</model>
</mule>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


David Dossot

unread,
Sep 24, 2010, 5:04:25 PM9/24/10
to us...@mule.codehaus.org
You probably want to use an expression transformer like this one:

#[attachments-list:{all}]

in order to fetch the attachments as a list. Then use a list message splitter to create one Mule message per attachment and dispatch these messages to a single service in charge of writing to file.

HTH
D.

Vladimir Baranov

unread,
Sep 24, 2010, 5:40:20 PM9/24/10
to us...@mule.codehaus.org
David, thank you for reply


I have attached 20091127.htm to plain text email.

Expression Evaluator "attachment" with expression "#[attachment:20091127]" returned null
Expression Evaluator "attachment" with expression "#[attachment:20091127.htm]" returned null

The attachment-list expression have also returned null.

That did not solve the problem. It is I am sure the right way to go, although I can't figure out the right configuration.

Does anyone have a working example of save attachments from the pop3/imap emails?

Edited by: Vladimir Baranov on Sep 24, 2010 2:39 PM

David Dossot

unread,
Sep 24, 2010, 6:10:04 PM9/24/10
to us...@mule.codehaus.org
The attachment-list expression have also returned null.

That is strange: when using '{all}' it returns null only if there is no attachment. Were you still using the mime-to-bytes-transformer? That is maybe the reason, as you are not "detaching" the attachments but just turning the whole MIME message into bytes. Try the email-to-string-transformer instead.

HTH
D.

Vladimir Baranov

unread,
Sep 27, 2010, 5:58:45 PM9/27/10
to us...@mule.codehaus.org
David,

Do you happen to have any sample source code that uses attachments-list:{all} expression-transformer?

Vladimir

David Dossot

unread,
Sep 27, 2010, 6:13:17 PM9/27/10
to us...@mule.codehaus.org
Vladimir,

Your question prompted me to search the source code and there I realized that in Mule 3, {all} is now *.

Do you mind trying with #[attachments-list:*] ?

Cheers,
D.

Vladimir Baranov

unread,
Sep 27, 2010, 6:32:58 PM9/27/10
to us...@mule.codehaus.org
it is not crashing now anymore. It is saving a list. now i have to figure out how to traverse through the list.

Thank you!

David Dossot

unread,
Sep 27, 2010, 6:38:20 PM9/27/10
to us...@mule.codehaus.org
Cool beans!

Don't traverse the list though: split if with a list message splitter and send each message to service that writes to file.

D.

Anand Koka

unread,
Sep 30, 2010, 3:56:49 PM9/30/10
to us...@mule.codehaus.org
I tried the same thing - I have the files being written out - all 0 bytes. It is complaining about not finding a the right transformer:

1. Could not find a transformer to transform "javax.mail.internet.MimeBodyPart" to "java.io.InputStream".

My configuration looks as:

<email:email-to-string-transformer name="EmailToByteMessage"/>
<expression-transformer name="getAttachment0">
<return-argument evaluator="attachment" expression="#attachment-list:{all}"/>
</expression-transformer>

...
<inbound>
<imap:inbound-endpoint connector-ref="mailIn"
host="mailserver"
port="245"
user="username"
password="password"
transformer-refs="EmailToByteMessage getAttachment0">

</imap:inbound-endpoint>
</inbound>
<echo-component/>
<outbound>
<multicasting-router>
<file:outbound-endpoint
path="email/inbox/msg"
outputPattern="${DATE:HH-mm-ss.SSS}-${COUNT}.dat"/>
</multicasting-router>
</outbound>

David Dossot

unread,
Sep 30, 2010, 4:43:26 PM9/30/10
to us...@mule.codehaus.org
1. Could not find a transformer to transform "javax.mail.internet.MimeBodyPart" to "java.io.InputStream".

Mmmh, this is probably due to the fact MimeBodyPart is not Serializable, hence no default transformer kicks in.

You can transform it into a payload with a simple expression transformer that calls getInputStream() on MimeBodyPart:

            <expression-transformer>
              <return-argument expression="payload.inputStream" evaluator="groovy" />
            </expression-transformer>

 
     <echo-component/>

You don't need this component.

 
     <outbound>
       <multicasting-router>
               <file:outbound-endpoint
                       path="email/inbox/msg"
                       outputPattern="${DATE:HH-mm-ss.SSS}-${COUNT}.dat"/>
       </multicasting-router>
     </outbound>

Why using a multicasting router? You have only a single endpoint so it doesn't make sense here. What you want to do is use a list message splitter to break your single message containing an attachment list into n messages each containing a single attachment:

<list-message-splitter-router>
  <file:outbound-endpoint
                          path="email/inbox/msg"
                          outputPattern="${DATE:HH-mm-ss.SSS}-${COUNT}.dat">
            <expression-transformer>
              <return-argument expression="payload.inputStream" evaluator="groovy" />
            </expression-transformer>
  </file:outbound-endpoint>
</list-message-splitter-router>

HTH
D.

Anand Koka

unread,
Oct 6, 2010, 8:03:55 AM10/6/10
to us...@mule.codehaus.org
David,

Thanks. I tried that configuration you suggested as below:

<email:email-to-string-transformer name="EmailToByteMessage"/>
<expression-transformer name="getAttachment0">

<return-argument evaluator="attachment" expression="#attachments-list:*"/>
</expression-transformer>


<service name="sample-service">


<inbound>
<imap:inbound-endpoint connector-ref="mailIn"
host="mailserver"

port="143"
user="username"
password="secret" transformer-refs="EmailToByteMessage getAttachment0">
</imap:inbound-endpoint>
</inbound>
<outbound>
<list-message-splitter-router>
<file:outbound-endpoint path="email/inbox/msg" outputPattern="last_${DATE}_email.txt">

<expression-transformer>
<return-argument expression="payload.inputStream"
evaluator="groovy" />
</expression-transformer>
</file:outbound-endpoint>
</list-message-splitter-router>

</outbound>
</service>

And it generated the following error:

********************************************************************************
Message : Failed to route event via endpoint: null. Message payload is of type: MimeBodyPart
Type : org.mule.api.routing.RoutingException
Code : MULE_ERROR-39999
JavaDoc : http://www.mulesource.org/docs/site/current2/apidocs/org/mule/api/routing/RoutingException.html
Payload : javax.mail.internet.MimeBodyPart@5f845f84
********************************************************************************
Exception stack is:
1. Object "javax.mail.internet.MimeBodyPart" not of correct type. It must be of type "java.util.List" (java.lang.IllegalArgumentException)
org.mule.routing.outbound.ListMessageSplitter:40 (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/IllegalArgumentException.html)
2. Failed to route event via endpoint: null. Message payload is of type: MimeBodyPart (org.mule.api.routing.RoutingException)
org.mule.routing.outbound.DefaultOutboundRouterCollection:97 (http://www.mulesource.org/docs/site/current2/apidocs/org/mule/api/routing/RoutingException.html)
********************************************************************************
Root Exception stack trace:
java.lang.IllegalArgumentException: Object "javax.mail.internet.MimeBodyPart" not of correct type. It must be of type "java.util.List"
at org.mule.routing.outbound.ListMessageSplitter.splitMessage(ListMessageSplitter.java:40)
at org.mule.routing.outbound.AbstractRoundRobinMessageSplitter.getMessageParts(AbstractRoundRobinMessageSplitter.java:92)
at org.mule.routing.outbound.AbstractMessageSplitter.route(AbstractMessageSplitter.java:37)
at org.mule.routing.outbound.DefaultOutboundRouterCollection$1.doInTransaction(DefaultOutboundRouterCollection.java:88)
at org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:45)
at org.mule.routing.outbound.DefaultOutboundRouterCollection.route(DefaultOutboundRouterCollection.java:93)
at org.mule.service.AbstractService.dispatchToOutboundRouter(AbstractService.java:867)
at org.mule.model.seda.SedaService.dispatchToOutboundRouter(SedaService.java:552)
at org.mule.model.seda.SedaService$ComponentStageWorker.run(SedaService.java:575)
at org.mule.work.WorkerContext.run(WorkerContext.java:310)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
at java.lang.Thread.run(Thread.java:811)

********************************************************************************

I really appreciate any further help.

David Dossot

unread,
Oct 9, 2010, 5:33:59 PM10/9/10
to us...@mule.codehaus.org
Hi,

I don't really understand this syntax:

<return-argument evaluator="attachment" expression="#attachments-list:*"/>

I think you want to use the attachments-list evaluator with the * expression:

<return-argument evaluator="attachments-list" expression="*"/>

HTH
D.

Anand Koka

unread,
Oct 11, 2010, 10:07:02 AM10/11/10
to us...@mule.codehaus.org
Sincerely, I do not understand the syntax. I was picking up different things from this thread - that could be the problem.

Thanks for keeping me straight here. I did change the syntax to what you specified. But my problem really is that with an email-to-string-converter on the inbound endpoint along with the attachment expression, it was complaining about the list-message-splitter not expecting a MimeBodyPart - but requires a java.util.List.

So, I used the other expression-transformer that you specified for payload.stream, and now I get the following error.

[10/11/10 10:00:27:289 EDT] 00000023 DefaultServic E org.mule.AbstractExceptionListener logException
********************************************************************************
Message : Expression Evaluator "attachments-list" with expression "*" returned null but a value was required.
Type : org.mule.api.transformer.TransformerException
Code : MULE_ERROR-65263
Transformer : ExpressionTransformer{this=2adc2adc, name='getAttachment0', ignoreBadInput=false, returnClass=class java.lang.Object, sourceTypes=[class java.lang.Object]}
JavaDoc : http://www.mulesource.org/docs/site/current2/apidocs/org/mule/api/transformer/TransformerException.html
********************************************************************************
Exception stack is:
1. Expression Evaluator "attachments-list" with expression "*" returned null but a value was required. (org.mule.api.transformer.TransformerException)
org.mule.expression.transformers.ExpressionTransformer:65 (http://www.mulesource.org/docs/site/current2/apidocs/org/mule/api/transformer/TransformerException.html)


********************************************************************************
Root Exception stack trace:

org.mule.api.transformer.TransformerException: Expression Evaluator "attachments-list" with expression "*" returned null but a value was required.
at org.mule.expression.transformers.ExpressionTransformer.transform(ExpressionTransformer.java:65)
at org.mule.transformer.AbstractMessageAwareTransformer.doTransform(AbstractMessageAwareTransformer.java:68)
at org.mule.transformer.AbstractTransformer.transform(AbstractTransformer.java:254)
at org.mule.DefaultMuleMessage.applyAllTransformers(DefaultMuleMessage.java:621)
at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:582)
at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:575)
at org.mule.DefaultMuleEvent.transformMessage(DefaultMuleEvent.java:326)
at org.mule.DefaultMuleEvent.transformMessage(DefaultMuleEvent.java:321)
at org.mule.component.simple.PassThroughComponent.doInvoke(PassThroughComponent.java:27)
at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:133)
at org.mule.component.AbstractComponent.invoke(AbstractComponent.java:161)
at org.mule.service.AbstractService.invokeComponent(AbstractService.java:929)
at org.mule.model.seda.SedaService.access$100(SedaService.java:56)
at org.mule.model.seda.SedaService$ComponentStageWorker.run(SedaService.java:574)


at org.mule.work.WorkerContext.run(WorkerContext.java:310)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
at java.lang.Thread.run(Thread.java:811)

********************************************************************************

But all that I am trying to do is simple - listen to an IMAP endpoint and copy the message and the attachment to a file location (my ultimate goal is to put those documents in an ECM solution).

Thanks
Anand

David Dossot

unread,
Oct 11, 2010, 3:33:16 PM10/11/10
to us...@mule.codehaus.org
Hi Anand,

I was trying to reproduce your problem and solve it by first switching to Mule 3 style then dig deeper in the issue:

  <flow name="sample-service">
    <imap:inbound-endpoint host="..." port="143" user="..." password="..." />
    
    <email:email-to-string-transformer />
      
    <expression-transformer>
      <return-argument evaluator="attachments-list" expression="*" />
    </expression-transformer>
    
    <collection-splitter />
    
    <expression-transformer>
      <return-argument expression="payload.inputStream" evaluator="groovy" />
    </expression-transformer>
    
    <file:outbound-endpoint path="/tmp/email" outputPattern="last_#[function:date]_email.txt" />
  </flow>

Alas, I can't test because of http://www.mulesoft.org/jira/browse/MULE-5138 :(

I'll have to come back to you when this bug will be killed.

Cheers,
D.

Anand Koka

unread,
Oct 12, 2010, 2:11:23 PM10/12/10
to us...@mule.codehaus.org
Vladimir,

Would you mind sharing with the group what configuration is working for you. As you can see in the thread, I am trying to do the same thing and save an attachment but not having any luck.

Thanks
Anand

Vladimir Baranov

unread,
Oct 14, 2010, 2:13:15 PM10/14/10
to us...@mule.codehaus.org
Here is my full configuration. I was away from work for couple days, hence the delay. I was able to get it to spit out the list of attachments, but have not saved the files yet.

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

<imap:connector name="imapConnector" backupEnabled="true" backupFolder="newBackup" checkFrequency="5000" mailboxFolder="INBOX" deleteReadMessages="false"/>

<file:connector name="receiveConnector">
<file:expression-filename-parser/>
</file:connector>


<email:mime-to-bytes-transformer name="EmailToByteMessage"/>
<email:email-to-string-transformer name="emailToString" />

<expression-transformer name="getAttachment0">
<return-argument evaluator="attachments-list" expression="#[attachments-list:*]"/>
</expression-transformer>

<model>
<service name="ServiceSaveEmailToFile">
<description>Save email to File</description>
<inbound>
<imap:inbound-endpoint user="USER" port="143" password="PASSWORD" host="HOST" disableTransportTransformer="true"/>
</inbound>

<outbound>

<list-message-splitter-router>


<file:outbound-endpoint path="./test" connector-ref="receiveConnector" transformer-refs="getAttachment0" outputPattern="mail-#[function:datestamp].pdf"/>

<payload-type-filter expectedType="java.util.List"/>
</list-message-splitter-router>

</outbound>
</service>
</model>
</mule>

Prince John

unread,
Oct 14, 2010, 2:32:38 PM10/14/10
to us...@mule.codehaus.org
Hello Anand / Vladimir

I'm trying to do something very similar - i.e. check a POP3 mail address and save the email body and subject into a database, and then attachments into a directory

Have either of you been successful with POP3? If so, could you please share the configuration

thanks, Prince J

Prince John

unread,
Oct 18, 2010, 11:24:04 PM10/18/10
to us...@mule.codehaus.org
Hi

Does anyone have a configuration to save attachments from POP3 with Mule?

thanks, Prince J

Andrew Perepelytsya

unread,
Oct 28, 2010, 8:48:30 AM10/28/10
to us...@mule.codehaus.org
David, there has been a workaround posted in jira comments since, in case you wondered.

HTH,
Andrew

Anand Koka

unread,
Oct 28, 2010, 11:54:12 AM10/28/10
to us...@mule.codehaus.org
Thanks Vladimir, I will give it a try.

Anand Koka

unread,
Oct 28, 2010, 5:05:57 PM10/28/10
to us...@mule.codehaus.org
Vladimir,

When I have the Payload Filter, nothing happens - other than the message that nothing matches the type of payload. When I don't have the Payload filter, it complains that a Mime Type Body Part is not compatible with java.util.List - which is what a List message splitter expects. Of course, one caveat is that I am still using 2.2 where as you appear to be using 3.0.

Any suggestions any one?

Thanks

Anand

Vladimir Baranov

unread,
Oct 28, 2010, 5:08:24 PM10/28/10
to us...@mule.codehaus.org
There are huge differences between 2.2 and 3.0. For example filters are specified "*" vs "{all}".

I can only offer suggestions if you will be using 3.0.

-Vladimir

Prince John

unread,
Oct 28, 2010, 10:14:37 PM10/28/10
to us...@mule.codehaus.org
On 10/29/10, Anand Koka <mule.us...@mulesource.com> wrote:
> Vladimir,
>
> When I have the Payload Filter, nothing happens - other than the message
> that nothing matches the type of payload. When I don't have the Payload
> filter, it complains that a Mime Type Body Part is not compatible with
> java.util.List - which is what a List message splitter expects. Of course,
> one caveat is that I am still using 2.2 where as you appear to be using 3.0.
>
> Any suggestions any one?

I tried something similar with POP3 but failed. Although not with
Mule, http://www.esbcompare.org/2010/10/download-email-and-save-attachments.html
seemed quite handy. Meanwhile I got tied up with other work, and I
will revisit this issue again later, and hopefully someone will share
a configuration with Mule by then

Thanks, Prince J

Anand Koka

unread,
Nov 1, 2010, 2:21:20 PM11/1/10
to us...@mule.codehaus.org
Vladimir,

So, I switched to Mule 3. I tried the configuration you have provided and I get 2 different errors.

First, with the payload filter in place, I get the following:
**********************************************************************
WARN 2010-11-01 14:17:10,071 [s1.2] org.mule.routing.outbound.DefaultOutboundRouterCollection: Message did not match an
y routers on: s1 and there is no catch all strategy configured on this router. Disposing message

Without the payload filter, I get the following:

**********************************************************************
* Application: mailqueue *
* OS encoding: Cp1252, Mule encoding: UTF-8 *
* *
* Agents Running: *
* JMX Agent *
* Wrapper Manager: Mule PID #5368, Wrapper PID #3832 *
**********************************************************************
ERROR 2010-11-01 14:10:24,304 [s1.2] org.mule.exception.DefaultServiceExceptionStrategy:
********************************************************************************
Message : Failed to route event via endpoint: org.mule.routing.outbound.ListMessageSplitter@788315. Messag
e payload is of type: String
Code : MULE_ERROR-39999
--------------------------------------------------------------------------------
Exception stack is:
1. Object "java.lang.String" not of correct type. It must be of type "java.util.List" (java.lang.IllegalArgumentExceptio
n)
org.mule.routing.outbound.ListMessageSplitter:40 (null)
2. Failed to route event via endpoint: org.mule.routing.outbound.ListMessageSplitter@788315. Message payload is of type:
String (org.mule.api.routing.RoutingException)
org.mule.routing.outbound.AbstractOutboundRouter:118 (http://www.mulesoft.org/docs/site/current2/apidocs/org/mule/api/
routing/RoutingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.IllegalArgumentException: Object "java.lang.String" not of correct type. It must be of type "java.util.List"


at org.mule.routing.outbound.ListMessageSplitter.splitMessage(ListMessageSplitter.java:40)
at org.mule.routing.outbound.AbstractRoundRobinMessageSplitter.getMessageParts(AbstractRoundRobinMessageSplitter

.java:95)
at org.mule.routing.outbound.AbstractMessageSplitter.route(AbstractMessageSplitter.java:45)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

This clearly indicates that I should have payload filter. However, there appears to be some other transformationn that needs to happen. I am trying to connect to Microsoft Exchange - not sure that is causing some other issues.

Thanks

Anand

Anand Koka

unread,
Nov 5, 2010, 3:33:19 PM11/5/10
to us...@mule.codehaus.org
I was able to get some developer help from Mulesoft. A transformer is necessary (but it is only a few lines of simple code) and it worked well. My only concern now is about 'naming' the files correctly with the names of the email attachments - haven't figured that one yet.

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

<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:imap="http://www.mulesource.org/schema/mule/imap/2.2"
xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
xmlns:file="http://www.mulesource.org/schema/mule/file/2.2"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.mulesource.org/schema/mule/imap/2.2 http://www.mulesource.org/schema/mule/imap/2.2/mule-imap.xsd
http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
http://www.mulesource.org/schema/mule/file/2.2 http://www.mulesource.org/schema/mule/file/2.2/mule-file.xsd">


<imap:connector name="imapConnector"/>
<vm:connector name="vmConnector" queueEvents="true"/>


<custom-transformer name="attachmentToInputStream"
class="DataHandlerToInputStream"/>


<expression-transformer name="returnAttachments">
<return-argument evaluator="attachments-list" expression="{all}" optional="false"/>
</expression-transformer>


<model name="testImap">
<service name="attachmentWriter">
<inbound>
<imap:inbound-endpoint user="user" password="password" host="imap.gmail.com" port="993"
transformer-refs="returnAttachments"/>
</inbound>


<outbound>
<list-message-splitter-router>
<file:outbound-endpoint path="./.mule/out" outputPattern="last_${DATE}_email.txt">
<transformer ref="attachmentToInputStream"/>
</file:outbound-endpoint>


</list-message-splitter-router>
</outbound>
</service>
</model>
</mule>

---------------------------------------------------------------------

Anand Koka

unread,
Nov 16, 2010, 11:06:07 AM11/16/10
to us...@mule.codehaus.org
Further help from Mulesoft developer has actually solved this problem.

Here is the config:

xmlns:smtp="http://www.mulesource.org/schema/mule/smtp/2.2"
xmlns:imap="http://www.mulesource.org/schema/mule/imap/2.2"
xmlns:email="http://www.mulesource.org/schema/mule/email/2.2"
xmlns:file="http://www.mulesource.org/schema/mule/file/2.2"
xmlns:jms="http://www.mulesource.org/schema/mule/jms/2.2"
xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
xsi:schemaLocation="
http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.mulesource.org/schema/mule/smtp/2.2 http://www.mulesource.org/schema/mule/smtp/2.2/mule-smtp.xsd
http://www.mulesource.org/schema/mule/imap/2.2 http://www.mulesource.org/schema/mule/imap/2.2/mule-imap.xsd
http://www.mulesource.org/schema/mule/email/2.2 http://www.mulesource.org/schema/mule/email/2.2/mule-email.xsd
http://www.mulesource.org/schema/mule/file/2.2 http://www.mulesource.org/schema/mule/file/2.2/mule-file.xsd
http://www.mulesource.org/schema/mule/jms/2.2 http://www.mulesource.org/schema/mule/jms/2.2/mule-jms.xsd
http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd">

<imap:connector name="mailIn"
mailboxFolder="INBOX"
checkFrequency="60000"
deleteReadMessages="true"/>
<smtp:connector name="mailOut"
contentType="text/plain"
fromAddress="donot...@company.com"
replyToAddresses="in...@company.com"/>


<vm:connector name="vmConnector" queueEvents="true"/>

<expression-transformer name="returnAttachments">
<return-argument evaluator="attachments-list" expression="{all}" optional="false"/>
</expression-transformer>

<file:connector name="fileName">
<file:expression-filename-parser/>
</file:connector>
<custom-transformer name="ImapTrans" class="org.mule.transport.email.transformers.TransformerImapToObject"/>
<custom-transformer name="ExtractMapfileName" class="org.mule.transport.email.transformers.ExtractMapfileName" />
<custom-transformer name="attachmentToInputStream"
class="org.mule.transport.email.transformers.DataHandlerToInputStream"/>
<model name="M2">
<service name="S2">


<inbound>
<imap:inbound-endpoint connector-ref="mailIn"

host="server"
port="143"
user="username"
password="password" transformer-refs="ImapTrans"/>
</inbound>
<outbound>
<list-message-splitter-router>
<vm:outbound-endpoint path="ListElement"/>
</list-message-splitter-router>
</outbound>
</service>
<service name="S3">
<inbound>
<vm:inbound-endpoint path="ListElement" transformer-refs="ExtractMapfileName"/>
</inbound>
<outbound>
<multicasting-router>
<file:outbound-endpoint path="./.mule/out" connector-ref="fileName" outputPattern="#[header:FileName]"/>
</multicasting-router>
</outbound>
</service>
</model>
</mule>

And the attached Java files. This worked for me in an embedded mule deployment (Websphere 6.1) going after an Exchange 2003 mail box. The file names are preserved and had to come up with a kludge to name the core message also as a .msg file.

Thanks

Anand

Gustav Rosen

unread,
Nov 30, 2010, 11:09:53 AM11/30/10
to us...@mule.codehaus.org
Hey, do you have the Java files you are referring to in your post about storing files from email attachments?
Thank you in advance.

Zeyu Wang

unread,
Aug 18, 2011, 10:50:49 PM8/18/11
to us...@mule.codehaus.org
Can you post the java files? Thanks

Lemmus Lemmus

unread,
Jan 18, 2012, 4:34:28 AM1/18/12
to us...@mule.codehaus.org
Is there a solution to this problem- has anybody got the files referred to ?

Kevin Jones

unread,
Nov 12, 2022, 4:03:26 AM11/12/22
to mule-user
If you want to IMAP/POP3 Save Attachments from Email? Try IMAP Attachments Extractor Tool will help you out if you want to extract attachments from IMAP server folders. The application allows exporting of selected extension attachments i.e. DOC, Excel, PDF, JPG, PNG, etc. This software supports the all Windows OS versions like - 11, 10, 8, 8.1, 7, XP, Vista, etc. You can easily install this software and try the free trial versions of the utility.

For more information visit here:- https://www.softakensoftware.com/imap-attachment-extractor.html
Reply all
Reply to author
Forward
0 new messages