问题
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