使用 java 邮件发送 html 内容
Sending htmlcontent using java mail
我正在尝试将以下 html 内容发送到邮件的 body。
内容仅显示数据。无边界 。 table header 没有背景色。当我单独执行下面的 html 内容时,它会显示所有这些。请帮助
StringBuilder builder = new StringBuilder();
builder.append("<!DOCTYPE html>");
builder.append("<html>");
builder.append("<head>");
builder.append("<style>");
builder.append("table {");
builder.append("width:100%;");
builder.append("}");
builder.append("table, th, td {");
builder.append("border: 1px solid black;");
builder.append("border-collapse: collapse;");
builder.append("}");
builder.append("th, td {");
builder.append("padding: 5px;");
builder.append("text-align: left;");
builder.append("}");
builder.append("table th {");
builder.append("background-color: lightblue;");
builder.append("color: black;");
builder.append("}");
builder.append("</style>");
builder.append("</head>");
builder.append("<body>");
builder.append("<table >");
builder.append("<tr>");
builder.append("<th>First Name</th>");
builder.append("<th>Last Name</th> ");
builder.append("<th>Points</th>");
builder.append("</tr>");
builder.append("<tr>");
builder.append("<td>Jill</td>");
builder.append("<td>Smith</td> ");
builder.append("<td>50</td>");
builder.append("</tr>");\
builder.append("</table>");
builder.append("</body>");
builder.append("</html>");
String report = builder.toString();
message.setContent(report,"text/html; charset=utf-8");
Transport.send(message);
邮件中没有显示边框。有没有什么很好的例子,其中 table 被发送到电子邮件 body,完美地显示了所有细节,包括颜色边框。
消息的显示方式取决于您使用的邮件reader。并非每封邮件 reader 都会像浏览器一样呈现所有可能的 html 内容。通常会禁止或忽略某些类型的内容,以防止出现安全问题。有时邮件 reader 将仅实现 html 的一个子集,足以显示最常见的 html 消息。
您使用什么邮件 reader 来显示您的消息?您将它们与哪些浏览器进行比较?
在我向 table 边框添加特定的 css 样式后问题得到解决。
我正在尝试将以下 html 内容发送到邮件的 body。 内容仅显示数据。无边界 。 table header 没有背景色。当我单独执行下面的 html 内容时,它会显示所有这些。请帮助
StringBuilder builder = new StringBuilder();
builder.append("<!DOCTYPE html>");
builder.append("<html>");
builder.append("<head>");
builder.append("<style>");
builder.append("table {");
builder.append("width:100%;");
builder.append("}");
builder.append("table, th, td {");
builder.append("border: 1px solid black;");
builder.append("border-collapse: collapse;");
builder.append("}");
builder.append("th, td {");
builder.append("padding: 5px;");
builder.append("text-align: left;");
builder.append("}");
builder.append("table th {");
builder.append("background-color: lightblue;");
builder.append("color: black;");
builder.append("}");
builder.append("</style>");
builder.append("</head>");
builder.append("<body>");
builder.append("<table >");
builder.append("<tr>");
builder.append("<th>First Name</th>");
builder.append("<th>Last Name</th> ");
builder.append("<th>Points</th>");
builder.append("</tr>");
builder.append("<tr>");
builder.append("<td>Jill</td>");
builder.append("<td>Smith</td> ");
builder.append("<td>50</td>");
builder.append("</tr>");\
builder.append("</table>");
builder.append("</body>");
builder.append("</html>");
String report = builder.toString();
message.setContent(report,"text/html; charset=utf-8");
Transport.send(message);
邮件中没有显示边框。有没有什么很好的例子,其中 table 被发送到电子邮件 body,完美地显示了所有细节,包括颜色边框。
消息的显示方式取决于您使用的邮件reader。并非每封邮件 reader 都会像浏览器一样呈现所有可能的 html 内容。通常会禁止或忽略某些类型的内容,以防止出现安全问题。有时邮件 reader 将仅实现 html 的一个子集,足以显示最常见的 html 消息。
您使用什么邮件 reader 来显示您的消息?您将它们与哪些浏览器进行比较?
在我向 table 边框添加特定的 css 样式后问题得到解决。