Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top