Conversion from MimeMessage to byte array

感情迁移 提交于 2019-12-13 10:46:49

问题


I need to convert MimeMessage into byte array, but while converting some characters are not coded correctly. Code lookis like this:

// message is MimeMessage
ByteArrayOutputStream baos = new ByteArrayOutputStream();
message.writeTo(baos);
byte[] bytes = baos.toByteArray(); 

This conversion doesn't work correctly, as output I'm receving wrong formatted email body:

<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D"en" lang=3D"en"
   >
<body style=3D"background-color: #ffffff;"  >

...

3D should not be present in this (xmlns=3D"http:). I could remove it but this is not a safe solution, I might accidentally remove some content from the email body.

Any tip may help.


回答1:


Your mime message contains Quoted-Printable Encoding, see MIME RFC 1521, so you need to decode it before saving it.

You should be able to use javax.mail.internet.MimeUtility.decode for this.



来源:https://stackoverflow.com/questions/8464686/conversion-from-mimemessage-to-byte-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!