Bober02
Bober02

Reputation: 15341

java mail - processing csv attachment

I am receiving e-mails set from a normal GUI client such as thunderbird or outlook, which conntain message body as String and one csv file attachment.

Using Java mail I would like to process the attachment i.e. read in the contet of the csv file into a String. Can I simply check whether the contet is a Multipart and then process the one at index 1 ( I guess e-mail body is at index 0)? Or should I check for dispositions which flags which part is an attachment? My only cocern is that if oe seds an e-mail using a regular GUI client, these flags are not set...

Any comments on what approach to take?

Upvotes: 0

Views: 2097

Answers (2)

Lorand Bendig
Lorand Bendig

Reputation: 10650

According to the Javamail tutorial

The content of your message is a Multipart object when it has attachments. You then need to process each Part, to get the main content and the attachment(s). Parts marked with a disposition of Part.ATTACHMENT from part.getDisposition() are clearly attachments...

Upvotes: 0

Bill Shannon
Bill Shannon

Reputation: 29971

This JavaMail FAQ entry will help.

Upvotes: 2

Related Questions