p:send-mail-003
Test p:send-mail sending multipart mail.
Test is expected to pass.
The pipeline
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:t="http://xproc.org/ns/testsuite/3.0" version="3.0">
<p:output port="result"/>
<p:option name="SHOST" select="'localhost'"
static="true"/>
<p:option name="SMTPPORT" select="1025" static="true"/>
<p:option name="APIPORT" select="1080" static="true"/>
<p:http-request href="http://{$SHOST}:{$APIPORT}/api/messages/"
method="delete">
<p:with-input>
<p:empty/>
</p:with-input>
</p:http-request>
<p:if test=".?code != 'OK'" name="check-delete">
<p:error code="Q{{http://example.com/}}irrelevant">
<p:with-input>
<p:empty/>
</p:with-input>
</p:error>
</p:if>
<p:send-mail parameters="map{'host': $SHOST, 'port': $SMTPPORT}"
auth="map{'username':'username','password':'password'}" depends="check-delete">
<p:with-input>
<p:inline>
<emx:Message xmlns:emx="URN:ietf:params:email-xml:"
xmlns:rfc822="URN:ietf:params:rfc822:">
<rfc822:from>
<emx:Address>
<emx:adrs>mailto:user@example.com</emx:adrs>
<emx:name>Example User</emx:name>
</emx:Address>
</rfc822:from>
<rfc822:to>
<emx:Address>
<emx:adrs>mailto:anotheruser@example.com</emx:adrs>
<emx:name>Another User</emx:name>
</emx:Address>
</rfc822:to>
<rfc822:subject>Multi-part Email</rfc822:subject>
<emx:content type="text/plain">
This is my text message.
</emx:content>
</emx:Message>
</p:inline>
<p:inline>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello, World</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my attachment.</p>
</body>
</html>
</p:inline>
</p:with-input>
</p:send-mail>
<p:sleep duration="1"/>
<p:http-request href="http://{$SHOST}:{$APIPORT}/api/messages/"
method="get"/>
<p:http-request href="http://{$SHOST}:{$APIPORT}/api/messages/"
method="get"/>
<p:http-request href="http://{$SHOST}:{$APIPORT}/api/messages/"
method="get"/>
<p:cast-content-type content-type="application/xml"/>
</p:declare-step>
Result
<map xmlns="http://www.w3.org/2005/xpath-functions"
xmlns:t="http://xproc.org/ns/testsuite/3.0">
<string key="code">OK</string>
<array key="data">
<map>
<array key="recipients_envelope">
<string>anotheruser@example.com</string>
</array>
<string key="sender_envelope">user@example.com</string>
<string key="subject">Multi-part Email</string>
<string key="created_at">2025-06-19T18:06:35</string>
<array key="recipients_message_cc"/>
<string key="source">Date: Thu, 19 Jun 2025 18:06:35 +0000 (UTC)
From: Example User <user@example.com>
To: Another User <anotheruser@example.com>
Message-ID: <915924206.3.1750356395336@f606fc24c444>
Subject: Multi-part Email
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_2_1023220556.1750356395334"
X-Peer: ('172.20.0.4', 47438)
X-MailFrom: user@example.com
X-RcptTo: anotheruser@example.com
------=_Part_2_1023220556.1750356395334
Content-Type: text/plain;charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
This is my text message.
------=_Part_2_1023220556.1750356395334
Content-Type: application/xml; name=nw-send-mail-003.xml
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=nw-send-mail-003.xml
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello, World</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my attachment.</p>
</body>
</html>
------=_Part_2_1023220556.1750356395334--
</string>
<string key="type">multipart/mixed</string>
<array key="recipients_message_to">
<string>Another User <anotheruser@example.com></string>
</array>
<number key="size">1078</number>
<string key="sender_message">Example User <user@example.com></string>
<array key="recipients_message_bcc"/>
<string key="peer">172.20.0.4:47438</string>
<number key="id">1</number>
</map>
</array>
<map key="meta">
<number key="pages_total">1</number>
</map>
</map>
Schematron checks
<s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron"
xmlns:t="http://xproc.org/ns/testsuite/3.0" queryBinding="xslt2">
<s:ns prefix="fn"
uri="http://www.w3.org/2005/xpath-functions"/>
<s:pattern name="Root must be map">
<s:rule context="/fn:map">
<s:assert test="fn:string[@key='code'] = 'OK'">Code must be 'OK'</s:assert>
<s:assert test="fn:array[@key='data']/fn:map/fn:string[@key='subject'] = 'Multi-part Email'">The subject must be correct</s:assert>
<s:assert test="fn:array[@key='data']/fn:map/fn:string[@key='type'] = 'multipart/mixed'">The content type must be multipart/mixed</s:assert>
</s:rule>
</s:pattern>
</s:schema>
Revision history
- 23 May 2025, Norm Tovey-Walsh
- Added static options for SMTP host and ports.
- 21 Apr 2025, Norm Tovey-Walsh
- Add dependencies for multithreading and a delay so sendri has time to process the message.
- 12 Oct 2024, Norm Tovey-Walsh
- Avoid content-type error if clearing the log fails.
- 30 May 2024, Norm Tovey-Walsh
- Test for the p:send-mail step.