mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
e8c4caaf74
commit
c0842455b9
@ -18,12 +18,7 @@ module.exports = function(RED) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var nodemailer = require("nodemailer");
|
var nodemailer = require("nodemailer");
|
||||||
var Imap = null;
|
var Imap = require('imap');
|
||||||
try {
|
|
||||||
Imap = require('imap');
|
|
||||||
} catch (e) {
|
|
||||||
util.log("[61-email.js] - imap npm not installed - no inbound email available");
|
|
||||||
}
|
|
||||||
|
|
||||||
//console.log(nodemailer.Transport.transports.SMTP.wellKnownHosts);
|
//console.log(nodemailer.Transport.transports.SMTP.wellKnownHosts);
|
||||||
|
|
||||||
@ -51,16 +46,10 @@ module.exports = function(RED) {
|
|||||||
if (flag) { RED.nodes.addCredentials(n.id,{userid:this.userid, password:this.password, global:true}); }
|
if (flag) { RED.nodes.addCredentials(n.id,{userid:this.userid, password:this.password, global:true}); }
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
var smtpTransport = nodemailer.createTransport("SMTP",{
|
var smtpTransport = nodemailer.createTransport({
|
||||||
//service: emailkey.service,
|
|
||||||
// {
|
|
||||||
//transport: 'SMTP',
|
|
||||||
host: node.outserver,
|
host: node.outserver,
|
||||||
port: node.outport,
|
port: node.outport,
|
||||||
requiresAuth: true,
|
secure: true,
|
||||||
secureConnection: true,
|
|
||||||
//domains: [ 'gmail.com', 'googlemail.com' ],
|
|
||||||
//},
|
|
||||||
auth: {
|
auth: {
|
||||||
user: node.userid,
|
user: node.userid,
|
||||||
pass: node.password
|
pass: node.password
|
||||||
@ -69,19 +58,28 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
node.status({fill:"blue",shape:"dot",text:"sending"});
|
|
||||||
if (smtpTransport) {
|
if (smtpTransport) {
|
||||||
|
node.status({fill:"blue",shape:"dot",text:"sending"});
|
||||||
|
var payload = msg.payload;
|
||||||
|
if (Buffer.isBuffer(payload)) {
|
||||||
|
payload = payload.toString();
|
||||||
|
} else if (typeof payload === "object") {
|
||||||
|
payload = JSON.stringify(payload);
|
||||||
|
} else if (typeof payload !== "string") {
|
||||||
|
payload = ""+payload;
|
||||||
|
}
|
||||||
|
|
||||||
smtpTransport.sendMail({
|
smtpTransport.sendMail({
|
||||||
from: node.userid, // sender address
|
from: node.userid, // sender address
|
||||||
to: node.name, // comma separated list of receivers
|
to: node.name, // comma separated list of receivers
|
||||||
subject: msg.topic, // subject line
|
subject: msg.topic, // subject line
|
||||||
text: msg.payload // plaintext body
|
text: payload // plaintext body
|
||||||
}, function(error, response) {
|
}, function(error, info) {
|
||||||
if (error) {
|
if (error) {
|
||||||
node.error(error);
|
node.error(error);
|
||||||
node.status({fill:"red",shape:"ring",text:"post error"});
|
node.status({fill:"red",shape:"ring",text:"send failed"});
|
||||||
} else {
|
} else {
|
||||||
node.log("Message sent: " + response.message);
|
node.log("Message sent: " + info.response);
|
||||||
node.status({});
|
node.status({});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -217,9 +215,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.emit("input",{});
|
node.emit("input",{});
|
||||||
}
|
}
|
||||||
if (Imap != null) {
|
RED.nodes.registerType("e-mail in",EmailInNode);
|
||||||
RED.nodes.registerType("e-mail in",EmailInNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
|
|
||||||
|
@ -40,7 +40,9 @@
|
|||||||
"cors":"2.2.0",
|
"cors":"2.2.0",
|
||||||
"mkdirp":"0.3.5",
|
"mkdirp":"0.3.5",
|
||||||
"cheerio":"0.15.0",
|
"cheerio":"0.15.0",
|
||||||
"uglify-js":"2.4.13"
|
"uglify-js":"2.4.13",
|
||||||
|
"nodemailer":"1.2.0",
|
||||||
|
"imap":"0.8.13"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"grunt": "0.4.4",
|
"grunt": "0.4.4",
|
||||||
|
Loading…
Reference in New Issue
Block a user