Search code examples
javasessionutf-8jakarta-mailmime

Set session property for UTF-8 support globally


The latest version of JavaMail 1.6.0 has introduced a new session property for enabling UTF8 support in mail addresses. (see changelog)

Properties props = new Properties();
props.put("mail.mime.allowutf8", true);
Session.getInstance(props)

We want to enable UTF-8 support globally in our project and a lot of classes (and libraries) create their own JavaMail sessions. Is it possible, to set a default value for a session property? Using a DefaultSession does not seem to be an option for security reasons.


Solution

  • Without the cooperation of the applications, there's no way to do this. Since this property should only be set when using a mail server that also supports the required extensions, setting it globally would not be safe.