From 088c429947d647f1a7d9b0b1963cee5d760ec2ad Mon Sep 17 00:00:00 2001 From: Thomas Theunen Date: Wed, 2 Mar 2022 16:01:02 +0100 Subject: [PATCH] Add example to send a on-the-fly generated PDF by mail --- .../cartridge/controllers/jsPDF.js | 95 ++++++++++++++++++- .../templates/default/mail/testMail.isml | 25 +++++ 2 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 cartridges/plugin_testlibraries/cartridge/templates/default/mail/testMail.isml diff --git a/cartridges/plugin_testlibraries/cartridge/controllers/jsPDF.js b/cartridges/plugin_testlibraries/cartridge/controllers/jsPDF.js index 7bb2145..4478274 100644 --- a/cartridges/plugin_testlibraries/cartridge/controllers/jsPDF.js +++ b/cartridges/plugin_testlibraries/cartridge/controllers/jsPDF.js @@ -3,8 +3,45 @@ var server = require('server'); var JSPDF = require('jsPDF'); -/** Just an example controller to test moment functions */ -server.get('Test', function () { +/** + * Encodes a string into a base64 string with an email-safe line width + * + * @param {string} str String the string to encode + * @param {string} characterEncoding String the character encoding (i.e. 'ISO-8859-1') + * + * @return {string} The encoded string + */ +function encodeBase64ForEmail(str, characterEncoding) { + var StringUtils = require('dw/util/StringUtils'); + var StringWriter = require('dw/io/StringWriter'); + var strBase64 = StringUtils.encodeBase64(str, characterEncoding); + var strBase64LB = ''; + var stringWriter = new StringWriter(); + + var offset = 0; + var length = 76; + + while (offset < strBase64.length) { + var maxOffset = offset + length; + + if (strBase64.length >= maxOffset) { + stringWriter.write(strBase64, offset, length); + stringWriter.write('\n'); + } else { + stringWriter.write(strBase64, offset, length - (maxOffset - strBase64.length)); + } + offset += length; + } + + stringWriter.flush(); + strBase64LB = stringWriter.toString(); + stringWriter.close(); + + return strBase64LB; +} + + +function generatePDF() { var jpg = 'data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABGAAD/4QMtaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVna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rr7lt2tlmYvC47DwiGxgbGBpUDVbFVRCtYiiy3kyCvngQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEAQBAEB//Z'; var doc = new JSPDF(); @@ -67,6 +104,60 @@ server.get('Test', function () { contents: 'This is text annotation (open by default)', open: true }); + return doc; +} + +/** + * Add files to the attributes to render the mail template. + * + * @param {dw.util.Map} mailAttributes - The mail attributes + */ +function addFilesToMailAttributes(mailAttributes) { + var Map = require('dw/util/HashMap'); + var files = new Map(); + + files.put('test.pdf', encodeBase64ForEmail(generatePDF().output(), 'ISO-8859-1')); + + mailAttributes.put('Base64FileMap', files); +} + +/** + * Just an example controller to test sending a mail with attachments + */ +server.get('Mail', function (req, res, next) { + var Template = require('dw/util/Template'); + var Mail = require('dw/net/Mail'); + var Map = require('dw/util/HashMap'); + + // Create the template that we will use to send the email. + var template = new Template('mail/testMail.isml'); + + // Work with a HashMap to pass the data to the template. + var mailAttributes = new Map(); + mailAttributes.put('EmailMessage', 'Test Message'); + + addFilesToMailAttributes(mailAttributes); + + var mail = new Mail(); + // Render the template with the data in the HashMap. + var content = template.render(mailAttributes); + + mail.addTo('thomas.theunen@forward.eu'); + mail.setFrom('info@forward.eu'); + mail.setSubject('Example Email'); + mail.setContent(content); + + res.json({ + success: mail.send().message, + content: content.getText() + }); + + next(); +}); + +/** Just an example controller to test moment functions */ +server.get('Test', function () { + var doc = generatePDF(); response.setContentType('application/pdf; charset=iso-8859-1'); diff --git a/cartridges/plugin_testlibraries/cartridge/templates/default/mail/testMail.isml b/cartridges/plugin_testlibraries/cartridge/templates/default/mail/testMail.isml new file mode 100644 index 0000000..e29a795 --- /dev/null +++ b/cartridges/plugin_testlibraries/cartridge/templates/default/mail/testMail.isml @@ -0,0 +1,25 @@ +--001a113414f6401b9c04f1451632 +Content-Type: multipart/alternative; boundary=001a113414f6401b8604f1451630 + +--001a113414f6401b8604f1451630 +Content-Type: text/plain; charset=ISO-8859-1 +Content-Transfer-Encoding: quoted-printable + + + +--001a113414f6401b8604f1451630 +Content-Type: text/html; charset=ISO-8859-1 +Content-Transfer-Encoding: quoted-printable + + + + + +--001a113414f6401b9c04f1451632 +Content-Type: application/pdf; name="${key}"; +Content-Description: ${key} +Content-Disposition: attachment; filename="${key}"; size=${fileContent.length}; creation-date="${(new Date()).toISOString()}"; modification-date="${(new Date()).toISOString()}" +Content-Transfer-Encoding: base64 + +${fileContent} +--001a113414f6401b9c04f1451632--