Intial Commit

This commit is contained in:
valki
2020-10-17 18:42:50 +02:00
commit 664c6d8ca3
5892 changed files with 759183 additions and 0 deletions

View File

@@ -0,0 +1,282 @@
<script type="text/x-red" data-template-name="e-mail">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-envelope"></i> <span data-i18n="email.label.to"></span></label>
<input type="text" id="node-input-name" placeholder="email@address.com">
</div>
<!-- <div class="form-row">
<label for="node-input-pin"><i class="fa fa-asterisk"></i> Service</label>
<select type="text" id="node-input-pin" style="width: 150px;">
<option value="-" disabled> </option>
<option value="DynectEmail">DynectEmail</option>
<option value="Gmail">Gmail</option>
<option value="hot.ee">hot.ee</option>
<option value="Hotmail">Hotmail</option>
<option value="iCloud">iCloud</option>
<option value="mail.ee">mail.ee</option>
<option value="Mail.Ru">Mail.Ru</option>
<option value="Mailgun">Mailgun</option>
<option value="Mailjet">Mailjet</option>
<option value="Mandrill">Mandrill</option>
<option value="Postmark">Postmark</option>
<option value="QQ">QQ</option>
<option value="QQex">QQex</option>
<option value="SendGrid">SendGrid</option>
<option value="SendCloud">SendCloud</option>
<option value="SES">SES</option>
<option value="Yahoo">Yahoo</option>
<option value="yandex">yandex</option>
<option value="Zoho">Zoho</option>
</select>
</div> -->
<div class="form-row">
<label for="node-input-server"><i class="fa fa-globe"></i> <span data-i18n="email.label.server"></span></label>
<input type="text" id="node-input-server" placeholder="smtp.gmail.com">
</div>
<div class="form-row">
<label for="node-input-port"><i class="fa fa-random"></i> <span data-i18n="email.label.port"></span></label>
<input type="text" id="node-input-port" placeholder="465" style="width:100px">
<label style="width:40px"> </label>
<input type="checkbox" id="node-input-secure" style="display:inline-block; width:20px; vertical-align:baseline;">
<span data-i18n="email.label.useSecureConnection"></span>
</div>
<div class="form-row">
<label for="node-input-userid"><i class="fa fa-user"></i> <span data-i18n="email.label.userid"></span></label>
<input type="text" id="node-input-userid">
</div>
<div class="form-row">
<label for="node-input-password"><i class="fa fa-lock"></i> <span data-i18n="email.label.password"></span></label>
<input type="password" id="node-input-password">
</div>
<br/>
<div class="form-row">
<label for="node-input-useTLS"><i class="fa fa-lock"></i> <span data-i18n="email.label.useTLS"></label>
<input type="checkbox" id="node-input-tls" style="display:inline-block; width:20px; vertical-align:baseline;">
</div>
<div class="form-row">
<label for="node-input-dname"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-input-dname" data-i18n="[placeholder]node-red:common.label.name">
</div>
<div class="form-tips" id="node-tip"><span data-i18n="[html]email.tip.cred"></span></div>
</script>
<script type="text/javascript">
(function() {
RED.nodes.registerType('e-mail',{
category: 'social-output',
color:"#c7e9c0",
defaults: {
server: {value:"smtp.gmail.com",required:true},
port: {value:"465",required:true},
secure: {value: true},
tls: {value: true},
name: {value:""},
dname: {value:""}
},
credentials: {
userid: {type:"text"},
password: {type: "password"},
global: { type:"boolean"}
},
inputs:1,
outputs:0,
icon: "envelope.png",
align: "right",
paletteLabel: function() {
return this._("email.email");
},
label: function() {
return this.dname||this.name||"email";
},
labelStyle: function() {
return (this.dname)?"node_label_italic":"";
},
oneditprepare: function() {
if (this.credentials.global) {
$('#node-tip').show();
} else {
$('#node-tip').hide();
}
}
});
})();
</script>
<script type="text/x-red" data-template-name="e-mail in">
<div class="form-row">
<label for="node-input-fetch"><i class="fa fa-hourglass-half"></i> <span data-i18n="email.label.getmail"></span></label>
<select type="text" id="node-input-fetch" style="width:130px;">
<option value="auto" data-i18n="email.label.auto"></option>
<option value="trigger" data-i18n="email.label.trigger"></option>
</select>
<span id="node-repeatTime">
<span style="margin-left:20px;" data-i18n="email.label.repeat"></span>
<input type="text" id="node-input-repeat" style="width:80px"> <span data-i18n="email.label.seconds">seconds</span>
</span>
</div>
<div class="form-row">
<label for="node-input-protocol"><i class="fa fa-envelope"></i> <span data-i18n="email.label.protocol"></span></label>
<select type="text" id="node-input-protocol">
<option value="IMAP">IMAP</option>
<option value="POP3">POP3</option>
</select>
</div>
<div class="form-row">
<label for="node-input-useSSL"><i class="fa fa-lock"></i> <span data-i18n="email.label.useSSL"></span></label>
<input type="checkbox" id="node-input-useSSL" style="width: auto;">
</div>
<div class="form-row">
<label for="node-input-server"><i class="fa fa-globe"></i> <span data-i18n="email.label.server"></span></label>
<input type="text" id="node-input-server" placeholder="imap.gmail.com">
</div>
<div class="form-row">
<label for="node-input-port"><i class="fa fa-random"></i> <span data-i18n="email.label.port"></span></label>
<input type="text" id="node-input-port" placeholder="993">
</div>
<div class="form-row">
<label for="node-input-userid"><i class="fa fa-user"></i> <span data-i18n="email.label.userid"></span></label>
<input type="text" id="node-input-userid">
</div>
<div class="form-row">
<label for="node-input-password"><i class="fa fa-lock"></i> <span data-i18n="email.label.password"></span></label>
<input type="password" id="node-input-password">
</div>
<div class="form-row node-input-box">
<label for="node-input-box"><i class="fa fa-inbox"></i> <span data-i18n="email.label.folder"></span></label>
<input type="text" id="node-input-box">
</div>
<div class="form-row node-input-disposition">
<label for="node-input-disposition"><i class="fa fa-trash"></i> <span data-i18n="email.label.disposition"></span></label>
<select type="text" id="node-input-disposition">
<option value="None" selected="selected" data-i18n="email.label.none"></option>
<option value="Read" data-i18n="email.label.read"></option>
<option value="Delete" data-i18n="email.label.delete"></option>
</select>
</div>
<div class="form-row">
<label for="node-input-criteria"><i class="fa fa-search"></i> <span data-i18n="email.label.criteria"></span></label>
<select type="text" id="node-input-criteria">
<option value="ALL" data-i18n="email.label.all"></option>
<option value="ANSWERED" data-i18n="email.label.answered"></option>
<option value="FLAGGED" data-i18n="email.label.flagged"></option>
<option value="SEEN" data-i18n="email.label.seen"></option>
<option value="UNANSWERED" data-i18n="email.label.unanswered"></option>
<option value="UNFLAGGED" data-i18n="email.label.unflagged"></option>
<option value="UNSEEN" selected="selected" data-i18n="email.label.unseen"></option>
<option value="_msg_" data-i18n="email.label.criteriaFromMsg"></option>
<!--
<option value="DELETED" data-i18n="email.label.delete"></option>
<option value="DRAFT" data-i18n="email.label.none"></option>
<option value="NEW" data-i18n="email.label.delete"></option>
<option value="UNDELETED" data-i18n="email.label.read"></option>
<option value="UNDRAFT" data-i18n="email.label.delete"></option>
<option value="RECENT" data-i18n="email.label.read"></option>
<option value="OLD" data-i18n="email.label.delete"></option>
-->
</select>
</div>
<br/>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
</div>
<script>
var checkPorts = function() {
var currentPort = $("#node-input-port").val();
if (currentPort === "143" || currentPort === "993" || currentPort === "110" || currentPort == "995") {
if ($("#node-input-useSSL").prop("checked") === true) {
$("#node-input-port").val($("#node-input-protocol").val() === "IMAP"?"993":"995");
} else {
$("#node-input-port").val($("#node-input-protocol").val() === "IMAP"?"143":"110");
}
}
};
$("#node-input-useSSL").change(function(x, y) {
// console.log("useSSL: x="+ JSON.stringify(x) + ", y=" + y);
// console.log("Value: " + $("#node-input-useSSL").prop("checked"));
checkPorts();
});
$("#node-input-protocol").change(function() {
var protocol = $("#node-input-protocol").val();
if (protocol === "IMAP") {
$(".node-input-box").show();
$(".node-input-disposition").show();
$(".node-input-criteria").show();
} else {
$(".node-input-box").hide();
$(".node-input-disposition").hide();
$(".node-input-criteria").hide();
}
checkPorts();
});
</script>
</script>
<script type="text/javascript">
(function() {
RED.nodes.registerType('e-mail in',{
category: 'social-input',
color:"#c7e9c0",
defaults: {
name: {value:""},
protocol: {value: "IMAP", required:true}, // Which protocol to use to connect to the mail server ("IMAP" or "POP3")
server: {value:"imap.gmail.com",required:true},
useSSL: {value: true},
port: {value:"993",required:true},
box: {value:"INBOX"}, // For IMAP, The mailbox to process
disposition: { value: "Read" }, // For IMAP, the disposition of the read email
criteria: {value: "UNSEEN"},
repeat: {value:"300",required:true},
fetch: {value:"auto"},
inputs: {value:0}
},
credentials: {
userid: {type:"text"},
password: {type: "password"},
global: { type:"boolean"}
},
inputs: 0,
outputs: 1,
icon: "envelope.png",
paletteLabel: function() {
return this._("email.email");
},
label: function() {
return this.name||this._("email.email");
},
labelStyle: function() {
return (this.name)?"node_label_italic":"";
},
oneditprepare: function() {
var that = this;
if (this.credentials.global) {
$('#node-tip').show();
} else {
$('#node-tip').hide();
}
if (typeof this.box === 'undefined') {
$("#node-input-box").val("INBOX");
this.box = "INBOX";
}
if (typeof this.criteria === 'undefined') {
$("#node-input-criteria").val("UNSEEN");
this.criteria = "UNSEEN";
}
if ($("#node-input-fetch").val() === null) { $("#node-input-fetch").val("auto"); }
$("#node-input-fetch").change(function() {
if ($("#node-input-fetch").val() === "trigger") {
$('#node-repeatTime').hide();
that.inputs = 1;
}
else {
$('#node-repeatTime').show();
that.inputs = 0;
}
});
}
});
})();
</script>

View File

@@ -0,0 +1,498 @@
/**
* POP3 protocol - RFC1939 - https://www.ietf.org/rfc/rfc1939.txt
*
* Dependencies:
* * poplib - https://www.npmjs.com/package/poplib
* * nodemailer - https://www.npmjs.com/package/nodemailer
* * imap - https://www.npmjs.com/package/imap
* * mailparser - https://www.npmjs.com/package/mailparser
*/
module.exports = function(RED) {
"use strict";
var nodemailer = require("nodemailer");
var Imap = require('imap');
var POP3Client = require("poplib");
var SimpleParser = require("mailparser").simpleParser;
var util = require("util");
if (parseInt(process.version.split("v")[1].split(".")[0]) < 8) {
throw "Error : Requires nodejs version >= 8.";
}
try {
var globalkeys = RED.settings.email || require(process.env.NODE_RED_HOME+"/../emailkeys.js");
}
catch(err) {
}
function EmailNode(n) {
RED.nodes.createNode(this,n);
this.topic = n.topic;
this.name = n.name;
this.outserver = n.server;
this.outport = n.port;
this.secure = n.secure;
this.tls = true;
var flag = false;
if (this.credentials && this.credentials.hasOwnProperty("userid")) {
this.userid = this.credentials.userid;
} else {
if (globalkeys) {
this.userid = globalkeys.user;
flag = true;
}
}
if (this.credentials && this.credentials.hasOwnProperty("password")) {
this.password = this.credentials.password;
} else {
if (globalkeys) {
this.password = globalkeys.pass;
flag = true;
}
}
if (flag) {
RED.nodes.addCredentials(n.id,{userid:this.userid, password:this.password, global:true});
}
if (n.tls === false) {
this.tls = false;
}
var node = this;
var smtpOptions = {
host: node.outserver,
port: node.outport,
secure: node.secure,
tls: {rejectUnauthorized: node.tls}
}
if (this.userid && this.password) {
smtpOptions.auth = {
user: node.userid,
pass: node.password
};
}
var smtpTransport = nodemailer.createTransport(smtpOptions);
this.on("input", function(msg, send, done) {
if (msg.hasOwnProperty("payload")) {
send = send || function() { node.send.apply(node,arguments) };
if (smtpTransport) {
node.status({fill:"blue",shape:"dot",text:"email.status.sending"});
if (msg.to && node.name && (msg.to !== node.name)) {
node.warn(RED._("node-red:common.errors.nooverride"));
}
var sendopts = { from: ((msg.from) ? msg.from : node.userid) }; // sender address
sendopts.to = node.name || msg.to; // comma separated list of addressees
if (node.name === "") {
sendopts.cc = msg.cc;
sendopts.bcc = msg.bcc;
sendopts.inReplyTo = msg.inReplyTo;
sendopts.replyTo = msg.replyTo;
sendopts.references = msg.references;
}
sendopts.subject = msg.topic || msg.title || "Message from Node-RED"; // subject line
if (msg.hasOwnProperty("envelope")) { sendopts.envelope = msg.envelope; }
if (Buffer.isBuffer(msg.payload)) { // if it's a buffer in the payload then auto create an attachment instead
if (!msg.filename) {
var fe = "bin";
if ((msg.payload[0] === 0xFF)&&(msg.payload[1] === 0xD8)) { fe = "jpg"; }
if ((msg.payload[0] === 0x47)&&(msg.payload[1] === 0x49)) { fe = "gif"; } //46
if ((msg.payload[0] === 0x42)&&(msg.payload[1] === 0x4D)) { fe = "bmp"; }
if ((msg.payload[0] === 0x89)&&(msg.payload[1] === 0x50)) { fe = "png"; } //4E
msg.filename = "attachment."+fe;
}
var fname = msg.filename.replace(/^.*[\\\/]/, '') || "file.bin";
sendopts.attachments = [ { content:msg.payload, filename:fname } ];
if (msg.hasOwnProperty("headers") && msg.headers.hasOwnProperty("content-type")) {
sendopts.attachments[0].contentType = msg.headers["content-type"];
}
// Create some body text..
sendopts.text = RED._("email.default-message",{filename:fname, description:(msg.description||"")});
}
else {
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
}
smtpTransport.sendMail(sendopts, function(error, info) {
if (error) {
node.error(error,msg);
node.status({fill:"red",shape:"ring",text:"email.status.sendfail",response:error.response,msg:{to:msg.to,topic:msg.topic,id:msg._msgid}});
} else {
node.log(RED._("email.status.messagesent",{response:info.response}));
node.status({text:"",response:info.response,msg:{to:msg.to,topic:msg.topic,id:msg._msgid}});
if (done) { done(); }
}
});
}
else { node.warn(RED._("email.errors.nosmtptransport")); }
}
else { node.warn(RED._("email.errors.nopayload")); }
});
}
RED.nodes.registerType("e-mail",EmailNode,{
credentials: {
userid: {type:"text"},
password: {type: "password"},
global: { type:"boolean"}
}
});
//
// EmailInNode
//
// Setup the EmailInNode
function EmailInNode(n) {
var imap;
RED.nodes.createNode(this,n);
this.name = n.name;
this.inputs = n.inputs;
this.repeat = n.repeat * 1000 || 300000;
if (this.repeat > 2147483647) {
// setTimeout/Interval has a limit of 2**31-1 Milliseconds
this.repeat = 2147483647;
this.error(RED._("email.errors.refreshtoolarge"));
}
if (this.inputs === 1) { this.repeat = 0; }
this.inserver = n.server || (globalkeys && globalkeys.server) || "imap.gmail.com";
this.inport = n.port || (globalkeys && globalkeys.port) || "993";
this.box = n.box || "INBOX";
this.useSSL= n.useSSL;
this.protocol = n.protocol || "IMAP";
this.disposition = n.disposition || "None"; // "None", "Delete", "Read"
this.criteria = n.criteria || "UNSEEN"; // "ALL", "ANSWERED", "FLAGGED", "SEEN", "UNANSWERED", "UNFLAGGED", "UNSEEN"
var flag = false;
if (this.credentials && this.credentials.hasOwnProperty("userid")) {
this.userid = this.credentials.userid;
} else {
if (globalkeys) {
this.userid = globalkeys.user;
flag = true;
} else {
this.error(RED._("email.errors.nouserid"));
}
}
if (this.credentials && this.credentials.hasOwnProperty("password")) {
this.password = this.credentials.password;
} else {
if (globalkeys) {
this.password = globalkeys.pass;
flag = true;
} else {
this.error(RED._("email.errors.nopassword"));
}
}
if (flag) {
RED.nodes.addCredentials(n.id,{userid:this.userid, password:this.password, global:true});
}
var node = this;
this.interval_id = null;
// Process a new email message by building a Node-RED message to be passed onwards
// in the message flow. The parameter called `msg` is the template message we
// start with while `mailMessage` is an object returned from `mailparser` that
// will be used to populate the email.
// DCJ NOTE: - heirachical multipart mime parsers seem to not exist - this one is barely functional.
function processNewMessage(msg, mailMessage) {
msg = RED.util.cloneMessage(msg); // Clone the message
// Populate the msg fields from the content of the email message
// that we have just parsed.
msg.payload = mailMessage.text;
msg.topic = mailMessage.subject;
msg.date = mailMessage.date;
msg.header = {};
mailMessage.headers.forEach((v, k) => {msg.header[k] = v;});
if (mailMessage.html) { msg.html = mailMessage.html; }
if (mailMessage.to && mailMessage.to.length > 0) { msg.to = mailMessage.to; }
if (mailMessage.cc && mailMessage.cc.length > 0) { msg.cc = mailMessage.cc; }
if (mailMessage.bcc && mailMessage.bcc.length > 0) { msg.bcc = mailMessage.bcc; }
if (mailMessage.from && mailMessage.from.value && mailMessage.from.value.length > 0) { msg.from = mailMessage.from.value[0].address; }
if (mailMessage.attachments) { msg.attachments = mailMessage.attachments; }
else { msg.attachments = []; }
node.send(msg); // Propagate the message down the flow
} // End of processNewMessage
// Check the POP3 email mailbox for any new messages. For any that are found,
// retrieve each message, call processNewMessage to process it and then delete
// the messages from the server.
function checkPOP3(msg) {
var currentMessage;
var maxMessage;
//node.log("Checking POP3 for new messages");
// Form a new connection to our email server using POP3.
var pop3Client = new POP3Client(
node.inport, node.inserver,
{enabletls: node.useSSL} // Should we use SSL to connect to our email server?
);
// If we have a next message to retrieve, ask to retrieve it otherwise issue a
// quit request.
function nextMessage() {
if (currentMessage > maxMessage) {
pop3Client.quit();
setInputRepeatTimeout();
return;
}
pop3Client.retr(currentMessage);
currentMessage++;
} // End of nextMessage
pop3Client.on("stat", function(status, data) {
// Data contains:
// {
// count: <Number of messages to be read>
// octect: <size of messages to be read>
// }
if (status) {
currentMessage = 1;
maxMessage = data.count;
nextMessage();
} else {
node.log(util.format("stat error: %s %j", status, data));
}
});
pop3Client.on("error", function(err) {
setInputRepeatTimeout();
node.log("error: " + JSON.stringify(err));
});
pop3Client.on("connect", function() {
//node.log("We are now connected");
pop3Client.login(node.userid, node.password);
});
pop3Client.on("login", function(status, rawData) {
//node.log("login: " + status + ", " + rawData);
if (status) {
pop3Client.stat();
} else {
node.log(util.format("login error: %s %j", status, rawData));
pop3Client.quit();
setInputRepeatTimeout();
}
});
pop3Client.on("retr", function(status, msgNumber, data, rawData) {
// node.log(util.format("retr: status=%s, msgNumber=%d, data=%j", status, msgNumber, data));
if (status) {
// We have now received a new email message. Create an instance of a mail parser
// and pass in the email message. The parser will signal when it has parsed the message.
SimpleParser(data, {}, function(err, parsed) {
//node.log(util.format("SimpleParser: on(end): %j", mailObject));
if (err) {
node.status({fill:"red", shape:"ring", text:"email.status.parseerror"});
node.error(RED._("email.errors.parsefail", {folder:node.box}), err);
}
else {
processNewMessage(msg, parsed);
}
});
pop3Client.dele(msgNumber);
}
else {
node.log(util.format("retr error: %s %j", status, rawData));
pop3Client.quit();
setInputRepeatTimeout();
}
});
pop3Client.on("invalid-state", function(cmd) {
node.log("Invalid state: " + cmd);
});
pop3Client.on("locked", function(cmd) {
node.log("We were locked: " + cmd);
});
// When we have deleted the last processed message, we can move on to
// processing the next message.
pop3Client.on("dele", function(status, msgNumber) {
nextMessage();
});
} // End of checkPOP3
//
// checkIMAP
//
// Check the email sever using the IMAP protocol for new messages.
var s = false;
var ss = false;
function checkIMAP(msg) {
//console.log("Checking IMAP for new messages");
// We get back a 'ready' event once we have connected to imap
s = true;
imap.once("ready", function() {
if (ss === true) { return; }
ss = true;
node.status({fill:"blue", shape:"dot", text:"email.status.fetching"});
//console.log("> ready");
// Open the inbox folder
imap.openBox(node.box, // Mailbox name
false, // Open readonly?
function(err, box) {
//console.log("> Inbox err : %j", err);
//console.log("> Inbox open: %j", box);
if (err) {
s = false;
node.status({fill:"red", shape:"ring", text:"email.status.foldererror"});
node.error(RED._("email.errors.fetchfail", {folder:node.box}),err);
imap.end();
setInputRepeatTimeout();
return;
}
else {
var criteria = ((node.criteria === '_msg_')?
(msg.criteria || ["UNSEEN"]):
([node.criteria]));
imap.search(criteria, function(err, results) {
if (err) {
node.status({fill:"red", shape:"ring", text:"email.status.foldererror"});
node.error(RED._("email.errors.fetchfail", {folder:node.box}),err);
imap.end();
s = false;
setInputRepeatTimeout();
return;
}
else {
//console.log("> search - err=%j, results=%j", err, results);
if (results.length === 0) {
//console.log(" [X] - Nothing to fetch");
node.status({results:0});
imap.end();
s = false;
setInputRepeatTimeout();
return;
}
var marks = false;
if (node.disposition === "Read") { marks = true; }
// We have the search results that contain the list of unseen messages and can now fetch those messages.
var fetch = imap.fetch(results, {
bodies: '',
struct: true,
markSeen: marks
});
// For each fetched message returned ...
fetch.on('message', function(imapMessage, seqno) {
//node.log(RED._("email.status.message",{number:seqno}));
//console.log("> Fetch message - msg=%j, seqno=%d", imapMessage, seqno);
imapMessage.on('body', function(stream, info) {
//console.log("> message - body - stream=?, info=%j", info);
SimpleParser(stream, {}, function(err, parsed) {
if (err) {
node.status({fill:"red", shape:"ring", text:"email.status.parseerror"});
node.error(RED._("email.errors.parsefail", {folder:node.box}),err);
}
else {
processNewMessage(msg, parsed);
}
});
}); // End of msg->body
}); // End of fetch->message
// When we have fetched all the messages, we don't need the imap connection any more.
fetch.on('end', function() {
node.status({results:results.length});
var cleanup = function() {
imap.end();
s = false;
};
if (this.disposition === "Delete") {
imap.addFlags(results, "\Deleted", cleanup);
} else if (this.disposition === "Read") {
imap.addFlags(results, "\Seen", cleanup);
} else {
cleanup();
}
setInputRepeatTimeout();
});
fetch.once('error', function(err) {
console.log('Fetch error: ' + err);
setInputRepeatTimeout();
});
}
}); // End of imap->search
}
}); // End of imap->openInbox
}); // End of imap->ready
node.status({fill:"grey",shape:"dot",text:"node-red:common.status.connecting"});
imap.connect();
} // End of checkIMAP
// Perform a check of the email inboxes using either POP3 or IMAP
function checkEmail(msg) {
if (node.protocol === "POP3") {
checkPOP3(msg);
} else if (node.protocol === "IMAP") {
if (s === false) { checkIMAP(msg); }
}
} // End of checkEmail
if (node.protocol === "IMAP") {
imap = new Imap({
user: node.userid,
password: node.password,
host: node.inserver,
port: node.inport,
tls: node.useSSL,
tlsOptions: { rejectUnauthorized: false },
connTimeout: node.repeat,
authTimeout: node.repeat
});
imap.on('error', function(err) {
if (err.errno !== "ECONNRESET") {
node.log(err);
s = false;
node.status({fill:"red",shape:"ring",text:"email.status.connecterror"});
}
setInputRepeatTimeout();
});
}
this.on("input", function(msg) {
checkEmail(msg);
});
this.on("close", function() {
if (this.interval_id != null) {
clearTimeout(this.interval_id);
}
if (imap) { imap.destroy(); }
});
function setInputRepeatTimeout() {
// Set the repetition timer as needed
if (!isNaN(node.repeat) && node.repeat > 0) {
node.interval_id = setTimeout( function() {
node.emit("input",{});
}, node.repeat );
}
ss = false;
}
if (this.inputs !== 1) { node.emit("input",{}); }
}
RED.nodes.registerType("e-mail in",EmailInNode,{
credentials: {
userid: { type:"text" },
password: { type: "password" },
global: { type:"boolean" }
}
});
};

View File

@@ -0,0 +1,14 @@
Copyright 2016 JS Foundation and other contributors, https://js.foundation/
Copyright 2013-2016 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -0,0 +1,74 @@
node-red-node-email
===================
<a href="http://nodered.org" target="info">Node-RED</a> nodes to send and receive simple emails.
Pre-requisite
-------------
You will need valid email credentials for your email server. For GMail this may mean
getting an application password if you have two-factor authentication enabled.
**Note :** Version 1.x of this node requires **Node.js v8** or newer.
Install
-------
Version 0.x of this node is usually installed by default by Node-RED.
As long as you have at least version 0.19.x of Node-RED you can install the new version
by using the `Menu - Manage Palette` option, or running the following command in your
Node-RED user directory - typically `~/.node-red`
cd ~/.node-red
npm i node-red-node-email
GMail users
-----------
If you are accessing GMail you may need to either enable <a target="_new" href="https://support.google.com/mail/answer/185833?hl=en">an application password</a>,
or enable <a target="_new" href="https://support.google.com/accounts/answer/6010255?hl=en">less secure access</a> via your Google account settings.</p>
Usage
-----
Nodes to send and receive simple emails.
### Input
Repeatedly gets emails from an IMAP or POP3 server and forwards them onwards as messages if not already seen.
The subject is loaded into `msg.topic` and `msg.payload` is the plain text body.
If there is text/html then that is returned in `msg.html`. `msg.from` and
`msg.date` are also set if you need them.
Additionally `msg.header` contains the complete header object including
**to**, **cc** and other potentially useful properties.
**Note:** this node *only* gets the most recent single email from the inbox,
so set the repeat (polling) time appropriately.
Uses the *imap* npm module.
### Output
Sends the `msg.payload` as an email, with a subject of `msg.topic`.
The default message recipient can be configured in the node, if it is left
blank it should be set using the `msg.to` property of the incoming message.
You may optionally override the *from* email address by setting `msg.from`,
otherwise the node will use the `userid` setting from the server connection.
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`. 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 <a href="https://nodemailer.com/message/attachments/" target="_new">nodemailer</a> format.
Uses the *nodemailer* npm module.

View File

@@ -0,0 +1,53 @@
<script type="text/html" data-help-name="e-mail">
<p>Sends the <code>msg.payload</code> as an email, with a subject of <code>msg.topic</code>.</p>
<p>The default message recipient can be configured in the node, if it is left
blank it should be set using the <code>msg.to</code> property of the incoming message. If left blank
you can also specify any or all of: <code>msg.cc</code>, <code>msg.bcc</code>, <code>msg.replyTo</code>, <code>msg.inReplyTo</code>, <code>msg.references</code> properties.</p>
<p>You may optionally set <code>msg.from</code> in the payload which will override the <code>userid</code>
default value.</p>
<h3>GMail users</h3>
<p>If you are accessing GMail you may need to either enable <a target="_new" href="https://support.google.com/mail/answer/185833?hl=en">an application password</a>,
or enable <a target="_new" href="https://support.google.com/accounts/answer/6010255?hl=en">less secure access</a> via your Google account settings.</p>
<h3>Details</h3>
<p>The payload can be html format.</p>
<p>If the payload is a binary buffer then it will be converted to an attachment.
The filename should be set using <code>msg.filename</code>. Optionally <code>msg.description</code> can be added for the body text.</p>
<p>Alternatively you may provide <code>msg.attachments</code> which should contain an array of one or
more attachments in <a href="https://nodemailer.com/message/attachments/" target="_new">nodemailer</a> format.</p>
<p>If required by your recipient you may also pass in a <code>msg.envelope</code> object, typically containing extra from and to properties.</p>
<p>If you have own signed certificates, Nodemailer can complain about that and refuse sending the message. In this case you can try switching off TLS.</p>
<p>Note: uses SMTP with SSL to port 465.</p>
</script>
<script type="text/html" data-help-name="e-mail in">
<p>Repeatedly gets emails from an IMAP server and forwards on as a msg if not already seen.</p>
<p>The subject is loaded into <code>msg.topic</code> and <code>msg.payload</code> is the plain text body.
If there is text/html then that is returned in <code>msg.html</code>. <code>msg.from</code> and <code>msg.date</code> are also set if you need them.</p>
<p>Additionally <code>msg.header</code> contains the complete header object including
<i>to</i>, <i>cc</i> and other potentially useful properties.</p>
<p>It can optionally mark the message as Read (default), Delete it, or leave unmarked (None).</p>
<p>Uses the imap module.</p>
<p><b>Note:</b> this node <i>only</i> gets the most recent single email from the inbox, so set the repeat (polling) time appropriately.</p>
<p>Note: uses IMAP with SSL to port 993.</p>
<p>Any attachments supplied in the incoming email can be found in the <code>msg.attachments</code> property. This will be an array of objects where
each object represents a specific attachments. The format of the object is:</p>
<pre>
{
contentType: // The MIME content description
fileName: // A suggested file name associated with this attachment
transferEncoding: // How was the original email attachment encodded?
contentDisposition: // Unknown
generatedFileName: // A suggested file name associated with this attachment
contentId: // A unique generated ID for this attachment
checksum: // A checksum against the data
length: // Size of data in bytes
content: // The actual content of the data contained in a Node.js Buffer object
// We can turn this into a base64 data string with content.toString('base64')
}
</pre>
<p>For POP3, the default port numbers are 110 for plain TCP and 995 for SSL. For IMAP the port numbers are 143 for plain TCP and 993 for SSL.</p>
<p>The maximum refresh interval is 2147483 seconds (24.8 days).</p>
</script>

View File

@@ -0,0 +1,63 @@
{
"email": {
"email": "email",
"label": {
"getmail":"Get mail",
"auto": "automatically",
"trigger": "when triggered",
"to": "To",
"server": "Server",
"port": "Port",
"useSecureConnection": "Use secure connection.",
"userid": "Userid",
"password": "Password",
"repeat": "every",
"seconds": "seconds",
"folder": "Folder",
"protocol": "Protocol",
"useSSL": "Use SSL?",
"useTLS": "Use TLS?",
"disposition": "Disposition",
"none": "None",
"read": "Mark Read",
"delete": "Delete",
"criteria": "Criteria",
"criteriaFromMsg": "- set from msg.criteria -",
"all": "All",
"answered": "Answered",
"flagged": "Flagged",
"seen": "Seen",
"unanswered": "Unanswered",
"unflagged": "Unflagged",
"unseen": "Unseen"
},
"default-message": "__description__\n\nFile from Node-RED is attached: __filename__",
"tip": {
"cred": "<b>Note:</b> Copied credentials from global emailkeys.js file.",
"recent": "Tip: Only retrieves the single most recent email."
},
"status": {
"messagesent": "Message sent: __response__",
"fetching": "fetching",
"foldererror": "fetch folder error",
"messageerror": "fetch message error",
"message": "message #__number__",
"newemail": "received new email: __topic__",
"duplicate": "duplicate not sent: __topic__",
"inboxzero": "you have achieved Inbox Zero",
"sending": "sending",
"sendfail": "send failed",
"connecterror": "connect error"
},
"errors": {
"nouserid": "No e-mail userid set",
"nopassword": "No e-mail password set",
"nocredentials": "No Email credentials found. See info panel.",
"nosmtptransport": "No SMTP transport. See info panel.",
"nopayload": "No payload to send",
"fetchfail": "Failed to fetch folder: __folder__",
"messageerror": "Fetch message error: __error__",
"refreshtoolarge": "Refresh interval too large. Limiting to 2147483 seconds"
}
}
}

View File

@@ -0,0 +1,40 @@
<!-- Source revision: https://github.com/node-red/node-red-nodes/commit/45e4c6d9d44b4e62b4be6b3e04728ebe306579f2 -->
<script type="text/html" data-help-name="e-mail">
<p><code>msg.payload</code>email<code>msg.topic</code></p>
<p>メッセージの受信者のデフォルトはノードに設定できます空のままとした場合は入力メッセージの<code>msg.to</code><code>msg.cc</code><code>msg.bcc</code><code>msg.replyTo</code><code>msg.inReplyTo</code><code>msg.references</code></p>
<p><code>msg.from</code><code>ID</code></p>
<p>ペイロードはHTML形式とすることも可能です</p>
<p>ペイロードにバイナリバッファを指定すると添付ファイルに変換しますファイル名は<code>msg.filename</code><code>msg.description</code></p>
<p><code>msg.attachments</code>に<a href="https://www.npmjs.com/package/nodemailer#attachments" target="_new">nodemailer</a>1</p>
<p>受信側で必要な場合には<code>msg.envelope</code>fromto</p>
<p>自己署名証明書を用いる場合Nodemailerはメッセージ送信を拒否することがありますその際はTLSを無効にしてみてください</p>
<p>: SMTP over SSLを465番ポートで利用</p>
</script>
<script type="text/html" data-help-name="e-mail in">
<p>IMAPサーバから<b>emailを一件</b></p>
<p>件名を<code>msg.topic</code><code>msg.payload</code>text/html<code>msg.html</code><code>msg.from</code><code>msg.date</code></p>
<p>さらに<code>msg.header</code>からヘッダオブジェクトを参照できます。ヘッダオブジェクトは<i>to</i><i>cc</i></p>
<p>この実装にはimapモジュールを利用しています</p>
<p><b>:</b> 1</p>
<p>: SMTP over SSLを993番ポートで利用します</p>
<p>入力メールに添付ファイルがある場合は<code>msg.attachments</code>:</p>
<pre>
{
contentType: // MIME項目種別
fileName: // 添付ファイルの想定ファイル名
transferEncoding: // 元の添付ファイルのエンコーディング
contentDisposition: // 不明
generatedFileName: // 添付ファイルの想定ファイル名
contentId: // 添付ファイルの一意な識別子
checksum: // データのチェックサム
length: // データのバイト数
content: // 実際のデータを表すNode.jsのバッファオブジェクト
// content.toString('base64')によりbase64形式の文字列に変換可能
}
</pre>
<p>POP3プロトコルでのデフォルトポート番号は素のTCPでは110番SSLでは995番ですIMAPプロトコルでは素のTCPでは143番SSLでは993番です</p>
</script>

View File

@@ -0,0 +1,49 @@
{
"email": {
"label": {
"to": "宛先",
"server": "サーバ",
"port": "ポート",
"useSecureConnection": "安全な接続を使用",
"userid": "ユーザID",
"password": "パスワード",
"repeat": "更新",
"seconds": "秒",
"folder": "フォルダ",
"protocol": "プロトコル",
"useSSL": "SSLを使用",
"disposition": "受信後の処理",
"none": "なし",
"read": "既読",
"delete": "削除",
"criteriaFromMsg": "- msg.criteriaから使用 -"
},
"default-message": "__description__\n\nNode-REDからファイルが添付されました: __filename__",
"tip": {
"cred": "<b>注釈:</b> emailkeys.jsファイルから認証情報をコピーしました。",
"recent": "注釈: 最新のメールを1件のみ取得します。"
},
"status": {
"messagesent": "メッセージを送信しました: __response__",
"fetching": "受信中",
"foldererror": "フォルダ受信エラー",
"messageerror": "メッセージ受信エラー",
"message": "メッセージ #__number__",
"newemail": "新しいe-mailを受信しました: __topic__",
"duplicate": "重複したメッセージは送信されません: __topic__",
"inboxzero": "受信トレイにメールがありません",
"sending": "送信中",
"sendfail": "送信が失敗しました",
"connecterror": "接続エラー"
},
"errors": {
"nouserid": "e-mailのユーザIDが設定されていません",
"nopassword": "e-mailのパスワードが設定されていません",
"nocredentials": "e-mailの認証情報がありません。「情報」タブを参照してください",
"nosmtptransport": "SMTP転送が設定されていません。「情報」タブを参照してください",
"nopayload": "送信するペイロードがありません",
"fetchfail": "フォルダの受信に失敗しました: __folder__",
"messageerror": "メッセージ受信エラー: __error__"
}
}
}

View File

@@ -0,0 +1,62 @@
{
"_from": "node-red-node-email@1.7.3",
"_id": "node-red-node-email@1.7.3",
"_inBundle": false,
"_integrity": "sha512-Svo9d/F6t8vNCWUBLbdIcGojUiLlOZ6mVx5Qldic48UwTwwZ+irFKqplQHU+rqBX+5XocWdR3sNaifEK6k7Kvw==",
"_location": "/node-red-node-email",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "node-red-node-email@1.7.3",
"name": "node-red-node-email",
"escapedName": "node-red-node-email",
"rawSpec": "1.7.3",
"saveSpec": null,
"fetchSpec": "1.7.3"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/node-red-node-email/-/node-red-node-email-1.7.3.tgz",
"_shasum": "02828208c47ab981eb35041f92cf0ea853eb1750",
"_spec": "node-red-node-email@1.7.3",
"_where": "/data",
"author": {
"name": "Dave Conway-Jones",
"email": "ceejay@vnet.ibm.com",
"url": "http://nodered.org"
},
"bundleDependencies": false,
"dependencies": {
"imap": "^0.8.19",
"mailparser": "^2.7.6",
"nodemailer": "^6.4.0",
"poplib": "^0.1.7"
},
"deprecated": false,
"description": "Node-RED nodes to send and receive simple emails",
"engines": {
"node": ">=8.0.0"
},
"keywords": [
"node-red",
"email",
"gmail",
"imap",
"pop"
],
"license": "Apache-2.0",
"name": "node-red-node-email",
"node-red": {
"nodes": {
"email": "61-email.js"
}
},
"repository": {
"type": "git",
"url": "https://github.com/node-red/node-red-nodes/tree/master/social/email"
},
"version": "1.7.3"
}