Loading TOC...

xdmp.email

xdmp.email(
   $message as Object
) as null

Summary

Send an email in a JavasCript 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 a JavaScript object that follows the format as below, or it can be an XML file that complies with the schema files for email (see xdmp:email).

Parameters
$message A JSON presentation of an email message to send. The message must comply with the following format:
{
  "cc" : {"user@yourdomain.com"},
  "comments" : "This is comment",
  "from" : {"name" : "sender", "address" : admin@marklogic.com},
  "reply-to" : {"group" : "team", "addresses": [ address1, address2]},
  "subject"  :  "JSON Email Format",
  "to" : {"addresses": [ address 1, address 2]},
  "content-type" : "multipart/mixed; boundary = blablabla",
  ...
  "content" : { "boundary" : "blablabla",
                "parts" : [
                            "Text part",
                            {
                             "Content-Type" : "image/jpeg",
                             "Disposition" : "attachment",
                             "filename": "sample_attachement_1.jpg",
                             "Content-Transfer-Encoding": "base64",
                             "attachment": encoded attachement 1
                             },

                             {
                               "Content-Type" : "image/jpeg",
                               "Disposition" : "attachment",
                               "filename": "sample_attachement_2.gif",
                               "Content-Transfer-Encoding": "base64",
                               "attachment": encoded attachement 2
                             }
                           ]
              }
}

Required Privileges

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

Example

// This example demonstrates sending a message with
// HTML content.
  
var from = {"name":"Administrator", "address":"admin@marklogic.com"};
var address1 = {"name":"user1", "address":"user1@yourdomain.com"};
var address2 = {"name":"user2", "address": "user2@yourdomain.com"};
var address3 = {"name":"user3","address":"user3@yourdomain.com"};
var contentType = "html"
var html = "<html>
              <head>
                <title>HTML message</title>
              </head>
              <body>
                <h1>Test Header</h1>
                <p>This is a sample paragraph</p>
              </body>
            </html>";
var message = {"from":from,
               "to":{"addresses":[address1, address2, address3]},
               "subject":"Test HTML email from ML Server",
               "content-type":contentType,
               "content":html
               };
xdmp.email(message);

Example

// This example demonstrates sending a message with
// plain text content.

var message = {"from":{"name":"Administrator", "address":"admin@marklogic.com"},
               "to":{"name":"username", "address":"user@yourdomain.com"},
               "subject":"Plain Text Message",
               "content":"Plain text content."};
xdmp.email(message);


Example

// This example demonstrates sending a message with
// attachments.
  
var boundary = "blahblahblah" + xdmp.random();
var contentType = "multipart/mixed; boundary=" + boundary;
var att1 = xs.base64Binary(fn.head(xdmp.documentGet("/path/to/the file1.jpeg")));
var att2 = xs.base64Binary(fn.head(xdmp.documentGet("/path/to/the file2.jpeg")));
var part1 = "This is a sample multipart message in JSON format";
var part2 = {
             "Content-Type": "image/jpeg",
             "Content-Disposition":"attachment",
             "filename":"file1.jpeg",
             "Content-Transfer-Encoding":"base64",
             "attachment":att1
            };
var part3 = {
             "Content-Type": "image/jpeg",
             "Content-Disposition":"attachment",
             "filename":"file2.jpeg",
             "Content-Transfer-Encoding":"base64",
             "attachment":att2
            };
var from = {"name":"Administrator", "address":"admin@marklogic.com"};
var to ={"address":"username@yourdomain.com"};
var subject = "Test JSON Multipart Message with Attachments!";
var message = {
               "from":from,
               "to":to,
               "subject": subject,
               "content-type":contentType,
               "content":{
                          "boundary":boundary,
                          "parts":[part1, part2, part3]
                         }
};
xdmp.email(message);

Comments

  • Hello! Is there any way to receive some feedback from xdmp.email() function like send success, exceptions? Regards.
  • the example // This example demonstrate sending a message with // plain text content. var message = {"from":{"name":"Administrator", "address":"admin@marklogic.com"}, "to":{"name":"username", "address":"user@yourdomain.com"}, "subject":"Plain Text Message", "content":"Plain text content."}; xdmp.email(message); does not work... response: [javascript] XDMP-ARGTYPE: xdmp.email({"from":{"name":"Administrator", "address":"admin@sensingclues.c...}) -- arg1 is not of type element() Stack Trace In undefined on line 9 In xdmp.email({"from":{"name":"Administrator", "address":"admin@sensingclues.c...}) ...
    • hugo, what version of MarkLogic did you see this in?
      • 8.0-4.2 bid old indeed...
        • Okay. I've filed a bug, which I'll update with that version number. We're up to 8.0-7, so if upgrading is an option, please consider doing so.
Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy