ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
mimeMessage.writeTo(outputStream);
That's the code where I write the entire email Mime content (including the headers) to an output stream because I didn't find any other way to copy the entire content as a string. This email needs to go out on an HTTP response as string. The getContent() only gives the body of the email. I need the entire header info, encoding, charset, content-type all on a string.
But when I have an html with the below content as the body of the email, the (') gets replaced with (?). I know this an encoding issue. But how to set the right encoding while writing to output stream?
<td class="email_monthlySummaryGraph_subTitle chart-subtitle" style="border: 0; color: #1D1D1D; font-family: Arial, sans-serif; font-size: 16px; line-height: 1.4; margin: 0; padding-bottom: 20px; padding-left: 0; padding-right: 0; padding-top: 0; text-align: center;" align="center">
That’s 5 kWh less than your highest week this month
</td>
I tried setting the encoding on
String response =
new String(
((ByteArrayOutputStream) resp).toByteArray(), StandardCharsets.UTF_8);
But I think it doesn't matter here coz by then, the characters are already replaced.