Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to extract a .eml (e-mail file) "attachment" from an e-mail

843830Mar 27 2006 — edited Jul 25 2008
Hi,

I have a slight problem with e-mail attachments. It's quite an explanation, so stick with me please.

I have to extend, debug and adapt an e-mail archive for my company.
I already worked on this project for 2 months, to make an extra batch and change some functionality of the existing e-mail archive.
I've been outsourced for a montsh, and now back on the e-mail archive.

There were some problems with e-mail attachments. (.gif, .doc, ...)
Some of them weren't shown in the web application.

The code that already has been written has a custom Email object. This e-mail object contains custom EmailBodyPart objects. Every EmailBodyPart has a disposition (Part.INLINE or Part.ATTACHMENT).
In every JavaMail Message object, every BodyPart is read, the disposition is extracted, and an EmailBodyPart is created with the disposition and some other data. Then, this EmailBodyPart is added to the Email object.

But sometimes, an attachment (.gif, .doc, ...) doesn't have the correct disposition in a Message, and isn't added as attachment, but as INLINE.
This way, in the web application, there aren't any attachments visible for the e-mail, but when you send the mail back to your inbox through the web interface, you can see the attachments again.

I had to solve this, and make the attachments visible in the web interface, and i did. I just checked if a filename was present, and if it wasn't an image (images still can be inline), then the disposition of the EmailBodyPart is set to Part.ATTACHMENT. It is visible now.

But now on to the problem...Sometimes, an e-mail (.eml file) is added to an other e-mail as an attachment. But, this e-mail isn't included as disposition attachment, but just as an other message within the message. It doesn't even have a file name. It seems like this is just a forward or something.

This e-mail should be visible as an attachment of the surrounding e-mail within the web interface. Does anyone have an idea how i can accomplish this and extract this body part as an attachment? Are there any headers i can check? (I printed the headers of the body part and there were only three, content-type, encoding en such ... but nothing like disposition. I tried to set the disposition to attachment to make it visible as an attachment, but that didn't work.

Thanks already in advance.

Comments

Bill Shannon-Oracle
What you're discovering is that not all mail applications create messages in
the way the MIME spec intends. You'll need some heuristics, as you've
already implemented. Maybe your best choice here is to assume any part
of type message/rfc822 is an "attachment", whether the Content-Disposition
says so or not.
843830
Hi there,

Thanks for your reply.

Well, it was kind of a mistake in the webapplication itself. The object passed to the related method was an instance of MimeMessage (the previous programmer only checked MimeMultiParts), and those weren't added to the vector of attachments. Now they are.

But now i still have problems. I have to give those attachments a file name. I tried extracting the subject from the message, but in the related method the message is casted to a multipart (is needed for further processing), and i can't fetch the sub-message's subject (if i get the part, i can't get the subject header anymore).

If i don't give the file a .eml extension, it opens a MHTML file or something, and it is unreadable by windows. If i get an InputStream of the part's content, and return that, and give the attachment a .eml extension, i get the outlook window , but all the text is pure HTML code. Not like it should be, and the mail in Outlook doesn't have any headers (no from, no to, no subject, ...)

Any idea here ? I could suply you with some code, but i don't understand all the steps myself, i got on this project which was build by someone else. It's quite a lot of code.

Thanks in advance.
Bill Shannon-Oracle
It's hard to tell from your description what the problem is.
Have you tried looking at the .eml file you're creating with
a text editor (e.g., notepad) to see if you have the correct
data in the file?
843830
Well, if i send the e-mail back to my inbox through the webapplication, i see the two attachments with their correct names. If i open them, i see the correct content (kind of a text file).
If i open it in wordpad, i see that the mail doesn't have any headers, and it seems that it starts like any regular HTML page, with a doctype tag at the top.

Well, it's kind of difficult to explain without code, but i'll have to select some code through all this bunch, cause there are a lot of references to other methods, it jumps throughout the whole application, and i don't understand all of it myself ... still have to work through the algoritm.

I'll try to give you some code.

Thx
843830
Hi,

This topic doesn't need any reply anymore. It's "solved"...
The .eml file attachments still can't be opened the correct way, but my manager told me to just display a message how many .eml file attachments are present, and to say in the message that if a user wants to open these attachments...the mail has to be sent back to his inbox.

Thank you all very much for helping me out (or trying to :-) ).
Kind regards.
843834
Hi,
I also have similar issue. I am trying to send an email with an attachment of type .eml. When I retrieve the mail sent, the eml file is dispalyed as part of base message where as it should be in the form of attachment like other item such as image, video etc. Can you please help in this.
Bill Shannon-Oracle
You're sending the mail using JavaMail? How are you constructing the message?
Did you read the FAQ item about forwarding messages?
843834
Email with attachment of type eml:::

When we send e-mail to my mailbox(My web appplication) with attachment of type eml then relay(where message processed) takes out the content (attachment and body text) of attachment of type eml and put it as part of base message. So in this case base message can contain more then one part of Content-Type: text/plain (one correspond to new message body and other correspond to attached eml message body).UI is not capable of showing both Content-types: text/plain, it just shows the first one and ignores other.
I am having this problem of not getting the eml file as an attachment but the content of eml file as part of my base message which gets displayed.
For e.g. if an eml files contains a file called 1.jpg and that eml file is attached to an email and sent to some ither email id. When I retrieve this email in my mailbox than instead of geting .eml file as atatchement I see 1.jpg as attachemnt which should not be the case........
Please suggest...
Bill Shannon-Oracle
I don't know what this "relay" is you're talking about, but it sounds like it's
reformatting the message in a way that breaks it. Maybe you should fix the
relay? If you're stuck sending your messages through a broken relay, there's
probably not anything you can do.
1 - 9
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 22 2008
Added on Mar 27 2006
9 comments
1,495 views