Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaMail API:在html类型的邮件内容中维护转义字符_Java_Jakarta Mail_Html Email - Fatal编程技术网

JavaMail API:在html类型的邮件内容中维护转义字符

JavaMail API:在html类型的邮件内容中维护转义字符,java,jakarta-mail,html-email,Java,Jakarta Mail,Html Email,我有一个要求,即接收用户输入的字符串形式,如: "Hi there,\r\n\r\nThe information is not visible in the page since you’ve adjusted the app.\r\n\r\ncan you please fix it?\r\n\r\nThanks,\r\n\r\nXYZ" 虽然在UI中看起来是这样的: Hi there, The information is not visible in the page since y

我有一个要求,即接收用户输入的字符串形式,如:

"Hi there,\r\n\r\nThe information is not visible in the page since you’ve adjusted the app.\r\n\r\ncan you please fix it?\r\n\r\nThanks,\r\n\r\nXYZ"
虽然在UI中看起来是这样的:

Hi there,

The information is not visible in the page since you’ve adjusted the app.

can you please fix it?

Thanks,

XYZ
我需要用
/r/n
解析上面的字符串,然后通过邮件将其发送给其他人

现在,当我在控制台中打印时,很明显,它的打印方式和它在UI中的外观一样

但是,当我试图将这个字符串作为
java邮件
内容时,我只是在检查收到的电子邮件时,将所有内容都放在一行中

邮件的内容类型设置为
text/html;字符集=utf-8
。我还尝试了
pre-wrap
样式,但没有成功

private static String createEmailContent(String descp) {

    StringBuilder sb = new StringBuilder("<style> div { white-space: pre-wrap;}</style><div>");
    sb.append(descp);
    sb.append("/<div>");
    return sb.toString();
}
私有静态字符串createEmailContent(字符串描述){
StringBuilder sb=新的StringBuilder(“div{white space:pre-wrap;}”);
某人附加(描述);
某人加上(“/”);
使某人返回字符串();
}

如何美化内容,使其看起来与收到的内容一模一样?

这是纯文本内容,只需将其作为text/plain而不是text/html发送即可


如果您真的需要将其作为文本/html发送,则需要处理数据,而不是html换行
或将其全部打包。

这是文本代码吗?如果是,将
/
更正为
是否有效?如果不考虑编写代码来插入<代码>
<代码>,而不是<代码> \r\n\/c>。没用。