How I can get base64 files from XML file and send them with email as attachments
Hi,
I have a case where receiving XML files with base64 (e.g. PDF)files inside the file which ones do I want to send as attachments in an email with Email Send connector (Template mode)
Unfortunately, you will not be able to use the Template mode of the EmailSend connector to dynamically generate a message with attachments - so it will not be possible to send a single message that contains your PDFs as attachments.
There is code that you can use in a previous step in the flow to scan this XML file, and decode and output the pdf’s as invidual messages. To do this, you’d need to use the xmlDOMSearch and encDecode operations to search the incoming document and output each file individually - you can also add headers to the message if there are other elements you need for the email body:
<!-- look for XPaths in the document --> <arc:set attr="xml.uri" value="ifilepath]" /> <arc:set attr="xml.xpath" value="/ForwardingInstructions/cac:DocumentReference" />
<arc:call op="xmlDOMSearch" in="xml"> <arc:if exp="cxpath('cbc:Status') | def | equals('Document')]"> <!-- here, you can add any other headers if you need more metadata in the email step --> <arc:set attr="output.header:ID" value="Dxpath(cbc:ID)]"/>
<!-- this code decodes the base64 data to a temp path on disk you'll need write permissions here --> <arc:set attr="output.filename" value="expath(cac:Attachment/cac:ExternalReference/cbc:Filename)]" /> <arc:set attr="enc.data" value="axpath(cac:Attachment/cbc:EmbeddedDocumentBinaryObject)]" /> <arc:set attr="enc.outfile" value="C:\\Temp\\Coutput.filename]" /> <arc:set attr="enc.format" value="BASE64" /> <arc:call op="encDecode" item="enc" />
<!-- this outputs the pdf as a new message --> <arc:set attr="output.filepath" value="henc.outfile]" /> <arc:push item="output" />
<!-- clean up the temp file --> <arc:set attr="del.file" value="eenc.outfile]" /> <arc:call op="fileDelete" item="del"/> </arc:if> </arc:call>
But note that this would output one file per PDF and each would send as a separate message in EmailSend in Attachment mode.
Unfortunately, you will not be able to use the Template mode of the EmailSend connector to dynamically generate a message with attachments - so it will not be possible to send a single message that contains your PDFs as attachments.
There is code that you can use in a previous step in the flow to scan this XML file, and decode and output the pdf’s as invidual messages. To do this, you’d need to use the xmlDOMSearch and encDecode operations to search the incoming document and output each file individually - you can also add headers to the message if there are other elements you need for the email body:
<!-- look for XPaths in the document --> <arc:set attr="xml.uri" value="ifilepath]" /> <arc:set attr="xml.xpath" value="/ForwardingInstructions/cac:DocumentReference" />
<arc:call op="xmlDOMSearch" in="xml"> <arc:if exp="cxpath('cbc:Status') | def | equals('Document')]"> <!-- here, you can add any other headers if you need more metadata in the email step --> <arc:set attr="output.header:ID" value="Dxpath(cbc:ID)]"/>
<!-- this code decodes the base64 data to a temp path on disk you'll need write permissions here --> <arc:set attr="output.filename" value="expath(cac:Attachment/cac:ExternalReference/cbc:Filename)]" /> <arc:set attr="enc.data" value="axpath(cac:Attachment/cbc:EmbeddedDocumentBinaryObject)]" /> <arc:set attr="enc.outfile" value="C:\\Temp\\Coutput.filename]" /> <arc:set attr="enc.format" value="BASE64" /> <arc:call op="encDecode" item="enc" />
<!-- this outputs the pdf as a new message --> <arc:set attr="output.filepath" value="henc.outfile]" /> <arc:push item="output" />
<!-- clean up the temp file --> <arc:set attr="del.file" value="eenc.outfile]" /> <arc:call op="fileDelete" item="del"/> </arc:if> </arc:call>
But note that this would output one file per PDF and each would send as a separate message in EmailSend in Attachment mode.
Hello @James B
Is it possible to send PDFs in one email with the same message header or if the filename begins the same? For example