gpt4 book ai didi

java - 无法测试 GMail 自定义操作

转载 作者:行者123 更新时间:2023-12-01 13:39:29 29 4
gpt4 key购买 nike

我一直在尝试测试GMail actions几天了,但似乎不起作用。由于我尚未注册,因此我使用下面的一小段 Java 代码通过 GMail 的 smtp 服务器向自己发送电子邮件。消息正文是文档的直接副本。

不过,Apps 脚本版本可以工作。

final String username = "david.hatanian@gmail.com";
final String password = "X";

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");

Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});

try {

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(username));
message.setSubject("Testing Subject");
message.setContent("<html>" +
" <head>" +
" <script type=\"application/ld+json\">" +
" {" +
" \"@context\": \"http://schema.org\"," +
" \"@type\": \"EmailMessage\"," +
" \"description\": \"Check this out\"," +
" \"action\": {" +
" \"@type\": \"ViewAction\"," +
" \"url\": \"https://www.youtube.com/watch?v=eH8KwfdkSqU\"" +
" }" +
" }" +
" </script>" +
" </head>" +
" <body>" +
" <p>" +
" This a test for a Go-To action in Gmail." +
" </p>" +
" </body>" +
"</html>", "text/html; charset=utf-8");

Transport.send(message);

System.out.println("Done");

} catch (MessagingException e) {
throw new RuntimeException(e);
}

最佳答案

即使是测试电子邮件也需要使用 DKIM/SPF 进行签名,以防止欺骗,而且我不确定是否有办法使用 SMTP 来做到这一点。

如果您不想使用 Apps 脚本,Google Apps 域(具有正确的 DKIM/SPF 配置)可能是您的最佳选择。

关于java - 无法测试 GMail 自定义操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20952662/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com