1

示例代码片段

MimeBodyPart htmlpart = new MimeBodyPart();
             htmlpart.setContent("<h1>Sample</h1><p>This is a sample HTML part","text/html");
             MimeBodyPart scriptcontent = new MimeBodyPart();

            // scriptcontent.setHeader("Content-Type", "application/ld+json");
             scriptcontent.setContent(" <script type=\"application/ld+json\">{ \"@context\":\"http://schema.org\",\"@type\":\"EmailMessage\",\"description\":\"Check this out\",\"action\": { \"@type\": \"ViewAction\",\"url\":\"https://www.youtube.com/\" } } </script>","application/ld+json");

             Multipart mp = new MimeMultipart();
             mp.addBodyPart(htmlpart);
             mp.addBodyPart(scriptcontent);

             mail.setContent(mp);

我已将脚本类型设置为 json+ld ,但我仍然收到一封没有查看操作的普通电子邮件。

4

1 回答 1

0

这样的事情有用吗?

MimeBodyPart htmlpart = new MimeBodyPart();
String html = "<html><h1>Sample</h1><p>This is a sample HTML part";
html += " <script type=\"application/ld+json\">{ \"@context\":\"http://schema.org\",\"@type\":\"EmailMessage\",\"description\":\"Check this out\",\"action\": { \"@type\": \"ViewAction\",\"url\":\"https://www.youtube.com/\" } } </script>";
html += "</html>";
htmlpart.setContent(html, "text/html");

Multipart mp = new MimeMultipart();
mp.addBodyPart(htmlpart);

mail.setContent(mp);
于 2014-03-21T15:01:33.620 回答