Search code examples
javajakarta-mail

Are there any constants for Java Mail standard properties? Is there any other way for ide/compiler to check their spelling?


All examples of Java Mail usage that I've found set properties for Session with property names defined as simple strings. Example:

   props.put("mail.smtp.auth", "true");
   props.put("mail.smtp.starttls.enable", "true");

As soon as documentation defines "standard" properties for Java Mail API, there might exist a way to check their correctness and autocomplete them in IDE.

However, I can't find such way using google/documentation. I also can't find any explanation for absence of predefined names.

So, is there any way to overcome this problem? Am I missing something obvious that makes an approach with constants impossible/unwanted?


Solution

  • No, there are no defined constants for these properties. Part of the reason why is that these properties are not completely constant - they're composed of some constant parts but also include the name of the protocol. The JavaMail reference implementation includes at least 8 protocols, so there would need to be 8 "constants" for each property. The property name needs to match the protocol that you're using; I don't know how an IDE would figure that out.