xdmp:email( $message as element(), [$options as (element()|map:map)?] ) as empty-sequence()
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
).
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>)
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>)
This example demonstrates sending a message with attachments. let $newline := " " 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>)
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> </em:Message>, <options xmlns="xdmp:email"> <authentication> <username>myname</username> <password>mypassword</password> </authentication> <verify-cert>true</verify-cert> </options>)
(:This example demonstrates sending a message that contains diacritic headers.:) let $newline := " " 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>=?utf-8?Q?Subject with diäcritic?=</rf:subject> <rf:from> <em:Address> <em:name>=?utf-8?Q?Diäcritic sender?=</em:name> <em:adrs>marklogic@yourdomain</em:adrs> </em:Address> </rf:from> <rf:to> <em:Address> <em:name>=?utf-8?Q?Diäcritic receiver?=</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>)