无法测试GMail自定义操作

我一直试图测试GMail的动作几天,但似乎没有用。 由于我没有注册,我使用下面的一小段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("" + " " + " " + " {" + " \"@context\": \"http://schema.org\"," + " \"@type\": \"EmailMessage\"," + " \"description\": \"Check this out\"," + " \"action\": {" + " \"@type\": \"ViewAction\"," + " \"url\": \"https://www.youtube.com/watch?v=eH8KwfdkSqU\"" + " }" + " }" + " " + " " + " " + " 

" + " This a test for a Go-To action in Gmail." + "

" + " " + "", "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配置)可能是您最好的选择。

Interesting Posts