Because you're sending an HTML email, you have to use <br />
instead of \r\n
, just like a classic HTML document (e.g. a .html
file). When you use \r\n
, the rendered content won't print a new line, but the source code of the mail will (and vice versa).
Newline character is not interpreted correctly in MimeMessage?
-
28-11-2021 - |
Domanda
StringBuffer emailMessage = new StringBuffer("Dear Scott");
emailMessage.append("\r\n");
emailMessage.append("Sending mail over internet");
So here is my formatted content when i inspect in debugger
Dear Scott,
Sending mail over internet
But when i receive it in thunderbird, i receive complete message in one line like below. Somehow newline character is not interpreted correctly when sending the content as html
Dear Scott,Sending mail over internet
here is how i am sending the message as html
MimeMessage msg = null;
msg = new MimeMessage(mailSession);
msg.setText(body, CHARSET_UTF_8, "html");
If i simply send the text as msg.setText(body, CHARSET_UTF_8) then i see the message in right format i.e "Sending mail over internet" in seen in next line. I am not getting why new line character is not interpreted correctly when sending the text as html?
Soluzione
Altri suggerimenti
HTML does not interpret newline characters. When you set the content type to "html", use "<br/>" instead of "\r\n":
StringBuffer emailMessage = new StringBuffer("Dear Scott");
emailMessage.append("<br/>");
emailMessage.append("Sending mail over internet");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow