我一直试图测试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);
}
答案 0 :(得分:1)
即使测试电子邮件需要使用DKIM / SPF签名以防止欺骗,我也不确定是否有办法通过SMTP进行此操作。
如果您不想使用Apps脚本,Google Apps域(具有正确的DKIM / SPF配置)可能是您最好的选择。