1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Allow msg.description to add to the email body text

(for feed from Fluickr node)
This commit is contained in:
dceejay 2015-02-08 15:02:02 +00:00
parent d4a27f88a1
commit 2dd572f5bd
2 changed files with 5 additions and 4 deletions

View File

@ -74,7 +74,7 @@
blank it should be set using the <b>msg.to</b> property of the incoming message.</p> blank it should be set using the <b>msg.to</b> property of the incoming message.</p>
<p>The payload can be html format.</p> <p>The payload can be html format.</p>
<p>If the payload is a binary buffer then it will be converted to an attachment. <p>If the payload is a binary buffer then it will be converted to an attachment.
The filename should be set using <b>msg.filename</b>.</p> The filename should be set using <b>msg.filename</b>. Optionally <b>msg.description</b> can be added for the body text.</p>
<p>Alternatively you may provide <b>msg.attachments</b> which should contain an array of one or <p>Alternatively you may provide <b>msg.attachments</b> which should contain an array of one or
more attachments in <a href="https://www.npmjs.com/package/nodemailer#attachments" target="_new">nodemailer</a> format.</p> more attachments in <a href="https://www.npmjs.com/package/nodemailer#attachments" target="_new">nodemailer</a> format.</p>
</script> </script>

View File

@ -76,13 +76,14 @@ module.exports = function(RED) {
} }
var sendopts = { from: node.userid }; // sender address var sendopts = { from: node.userid }; // sender address
sendopts.to = msg.to || node.name; // comma separated list of addressees 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 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")) { if (msg.hasOwnProperty("headers") && msg.headers.hasOwnProperty("content-type")) {
sendopts.attachments[0].contentType = msg.headers["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 { else {
var payload = RED.util.ensureString(msg.payload); var payload = RED.util.ensureString(msg.payload);