views:

159

answers:

1

Im sending mails from a web application running on a glassfish server, which was quite easy with the java mail API.

I'm starting now to attach files (mainly pdf and odt) to the mail, which works to, but the mime type of the attachment is not correctly set (application/octet-stream). I tried to attach the file with:

MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.attachFile(file);

and:

messageBodyPart = new MimeBodyPart();
FileDataSource source = new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(file.getName());

But its the same result. From here i have the hint to place a mime.types file in the META-INF folder of my application but this does not seem to work for me. I tried id in the META-INF of the war and the ear of my application.

Enabling debug for javax.activation gives me this:

INFO: MimetypesFileTypeMap: load HOME

INFO: MimetypesFileTypeMap: load SYS

INFO: MimetypesFileTypeMap: load JAR

INFO: MimetypesFileTypeMap: !anyLoaded

INFO: MimetypesFileTypeMap: not loading mime types file: /META-INF/mime.types

INFO: MimetypesFileTypeMap: load DEF

Where do i have to put the mime.types file or how can a mime types to my web application?

Thanks Raffael

A: 

Your application must be able to load "/META-INF/mime.types" as a resource from the classpath. Try to include it in a jar file in /WEB-INF/lib or place it in the /WEB-INF/classes/META-INF/mime.types.

jarnbjo
I placed it in /WEB-INF/classes/META-INF/. worked great. Thanks alot
raffael