saxon:send-mail

Sends an email message

send-mail($emailConfig as map(*), $subject as xs:string, $content as item(), $attachment as item()*) ➔ xs:boolean

Arguments

 

$emailConfig

map(*)

The email configuration

 

$subject

xs:string

The subject/title of the email

 

$content

item()

The body of the email

 

$attachment

item()*

Attachments to the email

Result

xs:boolean

Details

Namespace: http://saxon.sf.net/

This function takes four arguments:

  1. $emailConfig is a map, which contains configuration options required to send an email. The following key-value pairs are accepted:

    • smtp-server: required. The mail transfer agent will use the SMTP server specified here by the user to send the email message
    • to: required. Specifies the recipient of the email
    • from: optional. Specifies the sender of the email
    • username: optional. Specifies the username required by the email account
    • password: optional. Specifies the password required by the email account, which provides authentication on the server
    • realname: optional. Specifies the full name details of the sender of the email.
    • html: optional. Accepts an xs:boolean value: true() or false(), which specifies the serialization of the email content as html or plain text, respectively.
  2. $subject (xs:string) is the subject or title of the message. This is a string which the recipient of the email will typically see first, and provides a summary of the email content

  3. $content (either xs:string or element(html)) is an item which makes up the content of the email to be sent. This value presents the content as either plain text or html. Anything else is serialized as plain text.

  4. $attachment is sequence of items. This argument accepts a list of files to be attached to the email.

The function returns a boolean: true indicates email successfully sent, false indicates failure in sending email.

For example, the function may be used as follows in XSLT. This example constructs a variable to hold the mail-client configuration and constructs the content as html:

<xsl:variable name="mailSetup" select="map{'to':='recipient@example.com', 'from':='sender@example.com', 'smtp-server':='smtp.example.com', 'username':='user@example.com', 'password':='pass'}" /> <xsl:variable name="html"> <html> <body><h1>Saxonica Email</h1> <p>Test email</p> </body> </html> </xsl:variable> <xsl:value-of select="saxon:send-mail($mailSetup, 'Test email' , $html, ())" />

Notes on the Saxon implementation

Available since Saxon 9.5