开发者

Teaching javax.mail, javax.activation to recognize mime type of mail attachment in web application

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 开发者_JAVA技巧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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜