mail - check attachment valid contents if possible

to close #728
This commit is contained in:
Dave Conway-Jones
2021-01-12 12:41:41 +00:00
parent c0c6d75535
commit 14983c9722
3 changed files with 18 additions and 6 deletions

View File

@@ -120,7 +120,18 @@ module.exports = function(RED) {
var payload = RED.util.ensureString(msg.payload);
sendopts.text = payload; // plaintext body
if (/<[a-z][\s\S]*>/i.test(payload)) { sendopts.html = payload; } // html body
if (msg.attachments) { sendopts.attachments = msg.attachments; } // add attachments
if (msg.attachments && Array.isArray(msg.attachments)) {
sendopts.attachments = msg.attachments;
for (var a=0; a < sendopts.attachments.length; a++) {
if (sendopts.attachments[a].hasOwnProperty("content")) {
if (typeof sendopts.attachments[a].content !== "string" && !Buffer.isBuffer(sendopts.attachments[a].content)) {
node.error(RED._("email.errors.invalidattachment"),msg);
node.status({fill:"red",shape:"ring",text:"email.status.sendfail"});
return;
}
}
}
}
}
smtpTransport.sendMail(sendopts, function(error, info) {
if (error) {