开发者

Adding jpg extension in javamail

I have an image that I am trying to create as an attachment. I need to send the attachment as a jpg attachment. While I am able to send the attachment successfully, the file does not have the jpg extension. I am not clear how to add it.

    Message message =开发者_如何学Go new MimeMessage(session);
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(text);
Multipart multipart = new javax.mail.internet.MimeMultipart();
multipart.addBodyPart(messageBodyPart);
**DataSource source = new ByteArrayDataSource(image, "application/x-any");
messageBodyPart.setDataHandler(new DataHandler(source));**
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);


Try setting the correct mime type: image/jpg.
Furthermore, add the filename to your source: source.setFileName("myimage.jpg");

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜