XQuery/Sending E-mail

Motivation
You want to send an e-mail message from within an XQuery. This is frequently done when a report has finished running or when a key event such as a task update has been done.

Method
eXist provides a simple interface to e-mail.

Format of the send-email function
mail:send-email($email as element+, $server as xs:string?, $charset as xs:string?) xs:boolean+ where $email

The email message is in the following format:

$server	The SMTP server. If empty, then it tries to use the local sendmail program. $charset	The charset value used in the "Content-Type" message header (Defaults to UTF-8)

Example of JSON API
Many e-mail services also provide a JSON API. For example, Mandrill has an e-mail service that allows you to send your first 12,000 emails per month for free. After you register for an account they will provide you with an API key. This API key can be used with the following to send an e-mail message:

Below is a refined version of the above Mandrill script, which does not use the XQJSON module to serialize the XML message to JSON.

This example was provided by Chris Misztur on Sept. 21, 2013.