-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SMTP node. Allow expanding properties.
- Loading branch information
1 parent
940ba81
commit 862a3bb
Showing
13 changed files
with
132 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"key":"C77AE67918DAF5A819EE6EF2E9930554W2" | ||
"key":"C77AE67918DAF5A819EE6EF2E9930554W2", | ||
"crypt_algo":"aes-256-ctr" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"flow":{ | ||
"name":"Email file notification", | ||
"disabled":false | ||
}, | ||
"listener": { | ||
"type":"file", | ||
"isMessageGenerator": true, | ||
"path":"C:/test/in/*", | ||
"donePath":"C:/test/done" | ||
}, | ||
"route0":{ | ||
"type": "js", | ||
"dependencies":"listener", | ||
"module":"{{ESB_DIR}}/custom/email_custom.js" | ||
}, | ||
"output": { | ||
"type": "email", | ||
"dependencies":"route0", | ||
"host":"smtp.mailgun.org", | ||
"port": 465, | ||
"secure": true, | ||
"user": "[email protected]", | ||
"password": "<encrypted password goes here>", | ||
"to": "[email protected]", | ||
"from": "[email protected]", | ||
"title": "New request was submitted", | ||
"text": "New file has been submitted for processing.", | ||
"html": "<p>New file has been submitted for processing.</p>" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Email module. | ||
* | ||
* (C) 2020 TekMonks. All rights reserved. | ||
* See enclosed LICENSE file. | ||
*/ | ||
const nodemailer = require("nodemailer"); | ||
|
||
/** | ||
* Sends an email. | ||
* @param {*} to To email address | ||
* @param {*} from From email address | ||
* @param {*} title The subject of the email | ||
* @param {*} email_html The content of the email as HTML | ||
* @param {*} email_text The content of the email as Text | ||
* @param {*} attachments The set of attachments, format [{path: path/to/file},...] | ||
* @param {*} conf The config contains {host, port, secure, user, pass} for SMTP | ||
* @returns {result:true|false, response: Mailer response on true, error: Error on false} | ||
*/ | ||
module.exports.email = async function(to, from, title, email_html, email_text, attachments, conf) { | ||
const smtpConfig = { pool: true, host: conf.server, port: conf.port, secure: conf.secure, | ||
auth: {user: conf.user, pass: conf.pass} }, | ||
transporter = nodemailer.createTransport(smtpConfig); | ||
|
||
const nodeMailerAttachments = []; for (const attachment of attachments) nodeMailerAttachments.push({path:attachment}); | ||
|
||
try { | ||
const response = await transporter.sendMail({"from": from, "to": to, "subject": title, "text": email_text, | ||
"html": email_html, attachments: nodeMailerAttachments}); | ||
return {result: true, response}; | ||
} catch (err) { | ||
LOG.error(`Email send failed due to ${err}`); | ||
return {result: false, error: err}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* email.js - Sends email, output node | ||
* | ||
* (C) 2020 TekMonks. All rights reserved. | ||
*/ | ||
|
||
exports.start = require(`${CONSTANTS.ROOTDIR}/routes/email.js`).start; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* email.js - Sends an email via SMTP | ||
* | ||
* (C) 2018 TekMonks. All rights reserved. | ||
*/ | ||
const crypt = require(`${CONSTANTS.LIBDIR}/crypt.js`); | ||
const mailer = require(`${CONSTANTS.LIBDIR}/mailer.js`); | ||
|
||
exports.start = async (routeName, email, _messageContainer, message) => { | ||
if (message.env[routeName]?.isProcessing) return; | ||
if (!message.env[routeName]) message.env[routeName] = {isProcessing: true}; | ||
message.setGCEligible(false); | ||
|
||
// transfer email and email routing data, if specified, from the message content | ||
email.to = message.content.to || email.to; email.from = message.content.from || email.from; | ||
email.title = message.content.title || email.title; email.html = message.content.html; email.text = message.content.text; | ||
email.attachments = email.attachments || []; if (message.content.attachments) for (const attachment of message.content.attachments) email.attachments.push(attachment); | ||
|
||
LOG.info(`[EMAIL] Emailing ${email.to}, from ${email.from} with incoming message with timestamp: ${message.timestamp}`); | ||
|
||
if (!email.port) email.port = (email.secure?587:25); // handle ports | ||
|
||
const result = await mailer.email(email.to, email.from, email.title, | ||
email.html, email.text, email.attachments, { user: email.user, | ||
pass: crypt.decrypt(email.password), server: email.host, port: email.port, secure: email.secure }); | ||
|
||
if (result.result) { | ||
message.addRouteDone(routeName); | ||
delete message.env[routeName]; // clean up our mess | ||
message.setGCEligible(true); | ||
message.content = result.response; | ||
LOG.info(`[EMAIL] Email sent for message with timestamp: ${message.timestamp}`); | ||
LOG.debug(`[EMAIL] Response data is: ${result.response}`); | ||
} else { | ||
LOG.error(`[EMAIL] Email failed with error: ${result.error}, for message with timestamp: ${message.timestamp}`); | ||
message.addRouteError(routeName); | ||
delete message.env[routeName]; // clean up our mess | ||
message.setGCEligible(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters