-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Henry Gressmann <mail@explodingcamera.com>
- Loading branch information
1 parent
51c8e69
commit 5cae0b4
Showing
11 changed files
with
440 additions
and
28 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
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
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,58 @@ | ||
const nodemailer = require('nodemailer'); | ||
const xoauth2 = require('xoauth2'); | ||
const fs = require('fs-extra'); | ||
const nconf = require('nconf'); | ||
const ejs = require('ejs'); | ||
|
||
var Mailer = function () { | ||
const options = nconf.get('room:mail:options'); | ||
var _this = this; | ||
_this.test = 1; | ||
if (nconf.get('room:allowrecovery') || nconf.get('room:mail:confirmation')) { | ||
switch (nconf.get('room:mail:transport')) { | ||
case 'smtp': { | ||
_this.transporter = nodemailer.createTransport(options); | ||
break; | ||
} | ||
case 'xoauth': { | ||
const xoauth = xoauth2.createXOAuth2Generator({ | ||
user: options.auth.xoauth.user, | ||
clientId: options.auth.xoauth.clientId, | ||
clientSecret: options.auth.xoauth.clientSecret, | ||
refreshToken: options.auth.xoauth.refreshToken, | ||
accessToken: options.auth.xoauth.accessToken | ||
}); | ||
options.auth.xoauth = xoauth; | ||
_this.transporter = nodemailer.createTransport(options); | ||
break; | ||
} | ||
case 'direct': { | ||
const domain = nconf.get('room:mail:sender').split('@')[1]; | ||
options.name = domain; | ||
_this.transporter = nodemailer.createTransport(options); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
Mailer.prototype.sendEmail = function (type, opts, receiver, callback) { | ||
const html = ejs.render(fs.readFileSync(`socketserver/mail/templates/${type}.html`, 'utf8'), { | ||
opts, | ||
room: nconf.get('room'), | ||
}); | ||
|
||
const emailObj = { | ||
from: nconf.get('room:mail:sender'), | ||
to: receiver, | ||
subject: type.subject, | ||
html, | ||
}; | ||
|
||
this.transporter.sendMail(emailObj, (error, response) => { | ||
if (error) callback(error); | ||
else callback(null, response); | ||
}); | ||
}; | ||
|
||
module.exports = new Mailer(); |
Oops, something went wrong.