Skip to content

Commit

Permalink
Merge pull request #1 from pakitovic/mail-upgrade
Browse files Browse the repository at this point in the history
feat: upgrade nodemailer module
  • Loading branch information
CarlosCarmona authored Jun 27, 2019
2 parents bc0333b + 0004531 commit 1adf8cc
Show file tree
Hide file tree
Showing 11 changed files with 1,109 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#IDE
.vscode
api
#
node_modules
samples
19 changes: 5 additions & 14 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,10 @@
}
},
"rules": {
"indent": ["error", 2, {"SwitchCase":1}],
"indent": ["error", 2, { "SwitchCase": 1 }],
"default-case": "error",
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
]
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double"],
"semi": ["error", "always"]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
### Node template
# Logs
logs
*.log
Expand Down
35 changes: 35 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
### Node template
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules

#WebStorm
.idea/

#OS X
**.DS_Store
Empty file added .prettierignore
Empty file.
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 120,
"singleQuote": false,
"useTabs": false,
"tabWidth": 2,
"semi": true,
"bracketSpacing": true
}
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Mail notifier for [Runnerty]:

### Configuration sample:

```json
{
"id": "mail_default",
Expand All @@ -16,13 +17,13 @@
```

### Plan sample:

```json
{
"id":"mail_default",
"subject":"RUNNERTY SAMPLE",
"message":"Chain :CHAIN_NAME Running!"
"id": "mail_default",
"subject": "RUNNERTY SAMPLE",
"message": "Chain :CHAIN_NAME Running!"
}
```


[Runnerty]: http://www.runnerty.io
[runnerty]: http://www.runnerty.io
46 changes: 20 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class mailNotifier extends Notification {
}

send(notification) {
var _this = this;
var endOptions = {};
notification.to = (notification.to)?notification.to.toString():"";
notification.cc = (notification.cc)?notification.cc.toString():"";
notification.bcc = (notification.bcc)?notification.bcc.toString():"";
let _this = this;
let endOptions = {};
notification.to = notification.to ? notification.to.toString() : "";
notification.cc = notification.cc ? notification.cc.toString() : "";
notification.bcc = notification.bcc ? notification.bcc.toString() : "";

function readFilePromise(type, file) {
return new Promise(function (resolve, reject) {
fs.readFile(file, function (err, data) {
return new Promise((resolve, reject) => {
fs.readFile(file, (err, data) => {
let res = {};
if (err) {
res[type] = err;
Expand All @@ -43,8 +43,7 @@ class mailNotifier extends Notification {
filesReads.push(readFilePromise("text", txtTemplate));

Promise.all(filesReads)
.then(function (res) {

.then(res => {
let html_data;
let text_data;

Expand All @@ -59,7 +58,7 @@ class mailNotifier extends Notification {
textData.push(_this.replaceWith(text_data, notification));

Promise.all(textData)
.then(function (res) {
.then(res => {
let [html, text] = res;
let mailOptions = {
from: notification.from,
Expand All @@ -76,34 +75,29 @@ class mailNotifier extends Notification {
_this.logger("warn", "Mail sender is disable.");
endOptions.messageLog = "Mail sender is disable.";
_this.end(endOptions);

} else {
transport.sendMail(mailOptions,
function (err, res) {
if (err) {
endOptions.messageLog = "Mail sender:" + JSON.stringify(err);
_this.end(endOptions);
} else {
_this.end();
}
});
transport.sendMail(mailOptions, err => {
if (err) {
endOptions.messageLog = "Mail sender:" + JSON.stringify(err);
_this.end(endOptions);
} else {
_this.end();
}
});
}
})
.catch(function (err) {
.catch(err => {
endOptions.end = "error";
endOptions.messageLog = "Mail sender:" + JSON.stringify(err);
_this.end(endOptions);
});

})
.catch(function (err) {
.catch(err => {
endOptions.end = "error";
endOptions.messageLog = "Mail sender:" + JSON.stringify(err);
_this.end(endOptions);
});

}

}

module.exports = mailNotifier;
module.exports = mailNotifier;
Loading

0 comments on commit 1adf8cc

Please sign in to comment.