General Mail API

Last modified by Vincent Massol on 2024/07/05 17:44

cogMail APIs not related to sending emails
TypeJAR
Category
Developed by

XWiki Development Team

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard

Description

Obfuscation

  • Find out if email obfuscation is on or not:
    • from Java:
      @Inject
      private GeneralMailConfiguration configuration;
      ...
      if (configuration.shouldObfuscate())
      ...
    • From Velocity:
      $services.mail.general.shouldObfuscate()
  • Obfuscate an email address:
    • from Java:
      @Inject
      private EmailAddressObfuscator obfuscator;
      ...
      obfuscator.obfuscate(InternetAddress.parse("[email protected]")[0])
    • From Velocity:
      #if ($services.mail.general.obfuscate('[email protected]'))
      ...

HTML Displayer

An HTML Displayer for javax.mail.internet.InternetAddress is available, allowing to display an email address, either obfuscated (if configured, see the Mail Application) or not.

Example usage from Velocity:

{{velocity}}
#set ($email = $services.user.properties.email)
{{html}}
$services.display.html.display('javax.mail.internet.InternetAddress', $email)
{{/html}}
{{/velocity}}

or

{{velocity}}
#set ($email = $services.user.properties.email)
{{html}}
$services.display.html.display($email.class, $email)
{{/html}}
{{/velocity}}

Converters

We provide the following Converters:

  • java.lang.String <--> javax.mail.Address
  • java.lang.String <--> javax.mail.Address[]
  • java.lang.String <--> javax.mail.internet.InternetAddress Since 12.4RC1

This means for example that if you write some Velocity script and you're calling a method that accepts a javax.mail.Address, a javax.mail.internet.InternetAddress, or a javax.mail.Address[], you can pass the value as a String and it'll be converted to the target type. It also means that if you have these objects they can also be converted back to a String if the target type is a String.

For example the following will work even though setEmail's signature takes a javax.mail.internet.InternetAddress:

$services.user.properties.setEmail("[email protected]")

Get Connected