xdmp:email

xdmp:email(
   $message as element()
) as empty-sequence()

Summary

Send an email in an XQuery program. A valid SMTP Relay must be configured in the Groups page of the Admin Interface for the email to be sent. The format of the email message can be an XML file that complies with the schema files listed below, or it can be a JavaScript object that follows our definition of JSON email format (please see xdmp.email).

Parameters
$message An XML representation of an email message to send. The message must comply with the XML schemas defined in the following schema files:
  • install_dir/Config/email-xml.xsd
  • install_dir/Config/rfc822.xsd
where install_dir is the directory in which MarkLogic Server is installed.

Required Privileges

http://marklogic.com/xdmp/privileges/xdmp-email

Example

This example demonstrates sending a message with
HTML content.
  
xdmp:email(
<em:Message
 xmlns:em="URN:ietf:params:email-xml:"
 xmlns:rf="URN:ietf:params:rfc822:">
  <rf:subject>Sample HTML Email</rf:subject>
  <rf:from>
    <em:Address>
      <em:name>MarkLogic</em:name>
      <em:adrs>marklogic@yourdomain</em:adrs>
    </em:Address>
  </rf:from>
  <rf:to>
    <em:Address>
      <em:name>System Administrator</em:name>
      <em:adrs>admin@yourdomain</em:adrs>
    </em:Address>
  </rf:to>
  <em:content>
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>Test HTML message</title>
      </head>
      <body>
        <h1>Test HTML message</h1>
        <p>Here is a simple paragraph</p>
      </body>
    </html>
  </em:content>
</em:Message>)

Example

This example demonstrates sending a message with
plain text content.

xdmp:email(
<em:Message
 xmlns:em="URN:ietf:params:email-xml:"
 xmlns:rf="URN:ietf:params:rfc822:">
  <rf:subject>Sample Plain Text Email</rf:subject>
  <rf:from>
    <em:Address>
      <em:name>MarkLogic</em:name>
      <em:adrs>marklogic@yourdomain</em:adrs>
    </em:Address>
  </rf:from>
  <rf:to>
    <em:Address>
      <em:name>System Administrator</em:name>
      <em:adrs>admin@yourdomain</em:adrs>
    </em:Address>
  </rf:to>
  <em:content xml:space="preserve">
This is a sample email with a plain text body.
</em:content>
</em:Message>)

Example

This example demonstrates sending a message with
attachments.

let $newline := "&#13;&#10;"
let $boundary := concat("blah", xdmp:random())
let $content-type := concat("multipart/mixed; boundary=",$boundary)
let $attachment1 := xs:base64Binary(doc("/space/binaries/testdata1/Bon-Jovi.jpeg"))
let $attachment2 := xs:base64Binary(doc("/space/binaries/testdata1/logo.gif"))
let $content := concat(
  "--",$boundary,$newline,
  $newline,
  "This is a test email with two images attached.", $newline,
  "--",$boundary,$newline,
  "Content-Type: image/jpeg", $newline,
  "Content-Disposition: attachment; filename=Bon-Jovi.jpeg", $newline,
  "Content-Transfer-Encoding: base64", $newline,
  $newline,
  $attachment1, $newline,
  "--",$boundary,$newline,
  "Content-Type: image/gif", $newline,
  "Content-Disposition: attachment; filename=logo.gif", $newline,
  "Content-Transfer-Encoding: base64", $newline,
  $newline,
  $attachment2, $newline,
  "--",$boundary,"--", $newline)

return
  xdmp:email(
  <em:Message
    xmlns:em="URN:ietf:params:email-xml:"
    xmlns:rf="URN:ietf:params:rfc822:">
    <rf:subject>Sample Email</rf:subject>
    <rf:from>
      <em:Address>
        <em:name>MarkLogic</em:name>
        <em:adrs>marklogic@yourdomain</em:adrs>
      </em:Address>
    </rf:from>
    <rf:to>
      <em:Address>
        <em:name>System Administrator</em:name>
        <em:adrs>admin@yourdomain</em:adrs>
      </em:Address>
    </rf:to>
    <rf:content-type>{$content-type}</rf:content-type>
    <em:content xml:space="preserve">
      {$content}
    </em:content>
  </em:Message>)

Powered by MarkLogic Server | Terms of Use | Privacy Policy