Search code examples
gmailjakarta-mailgmail-api

How to use "confidential mode" of gmail using JavaMailSender


I was following this tutorial for setting up mail sender through spring-boot

I have been trying to add confidential mode through spring boot, there is no specific method as all supported mail providers not following the same method so using MimeMessage there is no predefined function.

I tried to look at the header of mail message which was sent in "confidential mode", so if they have added the confidential mode setup in the header, I would set header something like

helper.getMimeMessage().setHeader("Confidential", "on");
helper.getMimeMessage().setHeader("expiry", "5y");

But, they are not providing it through the header

  1. So, what can be done to achieve "confidential mode" programmatically?

Solution

    • For visibility purposes I'm addressing Bill Shannon comment which is totally correct. Gmail confidential mode its designed to be used within Gmail. If you use any other Email client to open a "confidential email" it will open a new window to open the message within Gmail. For more information, check the following link https://support.google.com/mail/answer/7674059.

    • I have checked within the list of possible API calls in OAuth Playground with the scope: https://mail.google.com/ which is the biggest scope for user.messages (which includes send and modify API calls), and I was unable to see any calls nor fields related to compose of confidential messages. Nor any documentation in the API Reference.

    • I have tested on my domain, and I was able to see that the messages on the recipient side has an additional header X-Gm-Locker which is generated by Gmail internally.

    Remember that if you want to send a message with this feature, you need to enable "Confidential mode" in Google Console https://support.google.com/a/answer/7684332?hl=en.

    TL;DR: In a nutshell, you can't send messages with "Confidential mode" through the Gmail API. Which affects the usage of JavaMailSender.