From 2dd572f5bddd23178c77e08b55c9460a1632365c Mon Sep 17 00:00:00 2001 From: dceejay Date: Sun, 8 Feb 2015 15:02:02 +0000 Subject: [PATCH] Allow msg.description to add to the email body text (for feed from Fluickr node) --- nodes/core/social/61-email.html | 2 +- nodes/core/social/61-email.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/nodes/core/social/61-email.html b/nodes/core/social/61-email.html index 196045ef7..cc660ee40 100644 --- a/nodes/core/social/61-email.html +++ b/nodes/core/social/61-email.html @@ -74,7 +74,7 @@ blank it should be set using the msg.to property of the incoming message.

The payload can be html format.

If the payload is a binary buffer then it will be converted to an attachment. - The filename should be set using msg.filename.

+ The filename should be set using msg.filename. Optionally msg.description can be added for the body text.

Alternatively you may provide msg.attachments which should contain an array of one or more attachments in nodemailer format.

diff --git a/nodes/core/social/61-email.js b/nodes/core/social/61-email.js index aa6900ef1..55d196c17 100644 --- a/nodes/core/social/61-email.js +++ b/nodes/core/social/61-email.js @@ -76,13 +76,14 @@ module.exports = function(RED) { } var sendopts = { from: node.userid }; // sender address sendopts.to = msg.to || node.name; // comma separated list of addressees - sendopts.subject = msg.topic || "Message from Node-RED"; // subject line + sendopts.subject = msg.topic || msg.title || "Message from Node-RED"; // subject line if (Buffer.isBuffer(msg.payload)) { // if it's a buffer in the payload then auto create an attachment instead - sendopts.attachments = [ { content: msg.payload, filename:(msg.filename || "file.bin") } ]; + sendopts.attachments = [ { content: msg.payload, filename:(msg.filename.replace(/^.*[\\\/]/, '') || "file.bin") } ]; if (msg.hasOwnProperty("headers") && msg.headers.hasOwnProperty("content-type")) { sendopts.attachments[0].contentType = msg.headers["content-type"]; } - sendopts.text = "Your file from Node-RED is attached : "+(msg.filename || "file.bin"); // holding body + // Create some body text.. + sendopts.text = "Your file from Node-RED is attached : "+(msg.filename.replace(/^.*[\\\/]/, '') || "file.bin")+ (msg.hasOwnProperty("description") ? "\n\n"+msg.description : ""); } else { var payload = RED.util.ensureString(msg.payload);