如何使用 java 在电子邮件正文中显示符号

How to display symbols in email body using java

我想在使用 Java 发送的 HTML 电子邮件正文中显示特殊字符或符号。以下是问题的详细信息。
我创建了扩展程序,它获取在网页表单的文本框中输入的所有文本,我将此文本存储在 String 变量中,并将此变量作为参数传递给负责发送电子邮件的方法。如果用户在文本框中输入“←”等特殊字符或符号,在邮件正文中显示为“→”,如何使用 java 处理这些特殊字符或符号,以便它们按原样显示在电子邮件正文中

这是我的代码的样子

String description = "Here I am getting all text from Text box in webpage, it can also  
contain special character as explained above";
String emailSubject = "test HTML email";
String emailBody =  "<!DOCTYPE html>" + "<html>" + "<body>" +
"<p>Please review this work item and assign it to the appropriate owner.</p>" + description+
            "</body>" + "</html>";  
//below is the method responsible for sending email to which I pass string parameters emailSubject   
//and emailBody  

将此添加到您的 html 标题部分:

<meta http-equiv="content-type" content="text/html;charset=utf-8" />

您可以用 HTML 个实体表示特殊符号。您基本上需要将符号映射到 HTML 实体并将它们替换为字符串。例如用户输入的箭头符号可以在HTML中替换为&larr;,在HTML中将显示为←。

您可以使用此 class 为您执行此操作: https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringEscapeUtils.html