使用Java';发送电子邮件时,我无法在gmail中获得查看操作;s邮件api

使用Java';发送电子邮件时,我无法在gmail中获得查看操作;s邮件api,java,email,google-schemas,Java,Email,Google Schemas,示例代码段 MimeBodyPart htmlpart = new MimeBodyPart(); htmlpart.setContent("<h1>Sample</h1><p>This is a sample HTML part","text/html"); MimeBodyPart scriptcontent = new MimeBodyPart(); // scriptcont

示例代码段

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);
MimeBodyPart htmlpart=new MimeBodyPart();
setContent(“示例这是一个示例HTML部分”,“text/HTML”);
MimeBodyPart scriptcontent=新的MimeBodyPart();
//setHeader(“内容类型”、“应用程序/ld+json”);
scriptcontent.setContent(“{\'@context\”:\”http://schema.org\“,\“@type\”:“EmailMessage\”,“description\”:“checkthis\”,“action\”:{\“@type\”:“ViewAction\”,“url\”:\”https://www.youtube.com/\“}}”、“应用程序/ld+json”);
Multipart mp=新的MimeMultipart();
mp.addBodyPart(htmlpart);
mp.addBodyPart(脚本内容);
mail.setContent(mp);

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

这样做有效吗

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);
MimeBodyPart htmlpart=new MimeBodyPart();
String html=“Sample这是一个示例html部分”;
html+=“{\'@context\”:\”http://schema.org\“,\“@type\”:“EmailMessage\”,“description\”:“checkthis\”,“action\”:{\“@type\”:“ViewAction\”,“url\”:\”https://www.youtube.com/\" } } ";
html+=“”;
setContent(html,“text/html”);
Multipart mp=新的MimeMultipart();
mp.addBodyPart(htmlpart);
mail.setContent(mp);

您是否尝试将脚本标记字符串连接到htmlpart?我不熟悉那个API,但似乎脚本标记应该是HTML主体部分的一部分,而不是单独的一部分。尝试了代码片段,它不起作用。我在某个地方读到邮件需要用DKIM或SPF进行数字签名,即使我们在邮寄自己的邮件。也许这会使它起作用。不过我不确定。