Pergunta

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 = "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);
}
Foi útil?

Solução

Even test emails need to be signed with DKIM/SPF in order to prevent spoofing, and I'm not sure if there's a way to do that with SMTP.

If you don't want to use Apps Script, a Google Apps domain (with proper DKIM/SPF configuration) is probably your best bet.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top