-
Notifications
You must be signed in to change notification settings - Fork 13
/
node_helper.js
57 lines (50 loc) · 1.95 KB
/
node_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Created by alexyak on 8/1/16.
* node_helper for camera module
*/
var NodeHelper = require('node_helper');
var nodemailer = require('nodemailer');
module.exports = NodeHelper.create({
transporter: null,
start: function(){
console.log(this.name + ' helper started ...');
},
socketNotificationReceived : function(notification, payload){
if (notification === 'INIT_MAILER'){
console.log('initializing nodemailer');
this.config = payload;
var self = this;
this.transporter = nodemailer.createTransport({
service: self.config.emailConfig.service,
auth: {
user: self.config.emailConfig.auth.user,
pass: self.config.emailConfig.auth.pass
},
logger: true, // log to console
debug: true // include SMTP traffic in the logs
});
}
else if (notification === 'SEND_EMAIL') {
this.config = payload.config;
var message = {
from: '[email protected]',
to: this.config.emailConfig.auth.user,
subject: 'Selfie from Magic Mirror',
attachments: [
{
path: payload.dataUrl
}
]
}
this.transporter.sendMail(message, function (error, info) {
if (error) {
console.log('Error occurred');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
console.log('Server responded with "%s"', info.response);
});
}
}
});