You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by John Kramer <ja...@ascenditsolutions.com> on 2014/01/27 19:59:52 UTC
POP3 ---> SMTP exception when attachments are used
Hello,
I have created the following route that pulls from a pop3 email account,
extracts some info, and then forwards the email on to an SMTP server to
different recipients depending on the use case.
.from("pop3://...&mapMailMessage=true")
.process( new SimpleSMTPSetupProcessor() )
.to("log:newmail")
.to("smtp://...&debugMode=true");
Note that SimpleSMTPSetupProcessor() is very simple - it clears the headers
and sets the new email addresses for the forwarded email. It does not change
the body or attachments.
For an email without attachments, everything works as desired. Also, Camel
does a great job of not deleting the POP3 email unless it is successfully
sent over the SMTP endpoint. However, if the original incoming email has an
attachment, I receive an exception (see two test cases below). I've tried
playing with the mapMailMessage option, yet no success. The exception
changes, but still, it's not working.
Clearly the above route isn't handling the attachments properly. My question
is, what's the best approach for handling this?
1) Should Camel automagically take care of the issue?
2) Is there a type converter that I should be using but I'm missing?
3) Camel shouldn't be responsible for this and I need to write the needed
code to build the proper outgoing MimeMesage?
Thanks!
John
Test 1
-----------------------------------------------------------------------------
Using "mapMailMessage=true" I see the following exception
DEBUG SMTP: IOException while sending, closing, THROW:
java.io.IOException: javax.mail.MessagingException: No MimeBodyPart content
at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:105)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:884)
at javax.activation.DataHandler.writeTo(DataHandler.java:317)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1485)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1773)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1119)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at
org.apache.camel.component.mail.DefaultJavaMailSender.send(DefaultJavaMailSender.java:128)
In this instance, the "log:newmail" shows the following for body info:
Exchange[ExchangePattern: InOnly, BodyType:
javax.mail.internet.MimeMultipart, Body:
javax.mail.internet.MimeMultipart@613278bf]
Test 2
-----------------------------------------------------------------------------
Using "mapMailMessage=false" I see the following exception:
javax.mail.IllegalWriteException: POP3 messages are read-only
at
com.sun.mail.pop3.POP3Message.saveChanges(POP3Message.java:546)[mail-1.4.7.jar:1.4.7]
at
org.apache.camel.component.mail.DefaultJavaMailSender.send(DefaultJavaMailSender.java:118)[camel-mail-2.12.2.jar:2.12.2]
In this instance, the "log:newmail" shows the following for body info:
Exchange[ExchangePattern: InOnly, BodyType: com.sun.mail.pop3.POP3Message,
Body: com.sun.mail.util.BASE64DecoderStream@7d7cb4ff]
--
View this message in context: http://camel.465427.n5.nabble.com/POP3-SMTP-exception-when-attachments-are-used-tp5746508.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: POP3 ---> SMTP exception when attachments are used
Posted by John Kramer <ja...@ascenditsolutions.com>.
I commented out the logging and enabled streamCaching. Still no luck:
java.io.IOException: javax.mail.MessagingException: No MimeBodyPart content
--
View this message in context: http://camel.465427.n5.nabble.com/POP3-SMTP-exception-when-attachments-are-used-tp5746508p5746570.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: POP3 ---> SMTP exception when attachments are used
Posted by John Kramer <ja...@ascenditsolutions.com>.
Claus,
>From the following link: "The type converter accepts the Exchange as an
optional 2nd parameter. This is usable if the type converter for instance
needs information from the current exchange."
http://camel.apache.org/type-converter.html
Based on that information, I think that I should be able to get the
attachments and build up the multipart mimemessage. I suppose that will also
yield a more unique method signature to ensure my typeconverter gets called.
However, I'm not looking for pain... so I'll test without the logging and
see if that changes the end result. To be honest, I hadn't interpreted the
exception to mean that the body was empty, but rather that the mimemessage
was missing the attachment parts. Or something to that effect... but this is
my first exposure to MimeMessages so I could be way off base.
Thanks,
John
--
View this message in context: http://camel.465427.n5.nabble.com/POP3-SMTP-exception-when-attachments-are-used-tp5746508p5746569.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: POP3 ---> SMTP exception when attachments are used
Posted by Claus Ibsen <cl...@gmail.com>.
Type converters is only for message body, and not for attachments.
Attachments is seldom used, in fact only camel-mail and camel-cxf
(SOAP w/ attachments) are some of the few using them.
Also be careful when logging. See this FAQ
http://camel.apache.org/why-is-my-message-body-empty.html
Not sure if that is causing the body to be empty and fail when sending
an attachment. But try without any logger etc.
On Tue, Jan 28, 2014 at 7:55 PM, John Kramer
<ja...@ascenditsolutions.com> wrote:
> Is this the approach that I should use?
> http://camel.apache.org/type-converter.html
>
> Here's my fear about proceeding along that path: Since camel isn't throwing
> a NoTypeConversionAvailableException exception, then my guess is that Camel
> is already using a type converter that it thinks works properly. If I create
> a new type converter to properly handle attachments, how do I even know that
> camel will select it?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/POP3-SMTP-exception-when-attachments-are-used-tp5746508p5746565.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Make your Camel applications look hawt, try: http://hawt.io
Re: POP3 ---> SMTP exception when attachments are used
Posted by John Kramer <ja...@ascenditsolutions.com>.
Is this the approach that I should use?
http://camel.apache.org/type-converter.html
Here's my fear about proceeding along that path: Since camel isn't throwing
a NoTypeConversionAvailableException exception, then my guess is that Camel
is already using a type converter that it thinks works properly. If I create
a new type converter to properly handle attachments, how do I even know that
camel will select it?
--
View this message in context: http://camel.465427.n5.nabble.com/POP3-SMTP-exception-when-attachments-are-used-tp5746508p5746565.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: POP3 ---> SMTP exception when attachments are used
Posted by John Kramer <ja...@ascenditsolutions.com>.
I believe that I've done what I can to make option (1) work - i.e. enable
Camel to automatically handle the message conversion properly. So I've moved
on to option (2) to see if there is an out-of-the-box Camel type converter
that I can use. However googling the issue hasn't been promising. Anyone
have any guidance along these lines?
thanks,
John
--
View this message in context: http://camel.465427.n5.nabble.com/POP3-SMTP-exception-when-attachments-are-used-tp5746508p5746551.html
Sent from the Camel - Users mailing list archive at Nabble.com.