I have been trying to test GMail actions for a few days but it does not seem to work. Since I am not registered I use the little piece of Java code below to send an email from myself to myself using GMail's smtp servers. The message's body is a direct copy from the documentation.
The Apps Script version works, though.
final String username = "[email protected]";
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);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…