Start working on nodemailer upgrade

This commit is contained in:
Calvin Montgomery 2017-09-25 22:31:45 -07:00
parent 071def0838
commit 9cfe71d4c4
4 changed files with 111 additions and 1 deletions

View file

@ -0,0 +1,29 @@
class EmailConfig {
constructor(config) {
this.config = config;
}
getPasswordReset() {
const reset = this.config['password-reset'];
return {
getHTML() {
return reset['html-template'];
},
getText() {
return reset['text-template'];
},
getFrom() {
return reset['from'];
},
getSubject() {
return reset['subject'];
}
};
}
}
export { EmailConfig };

31
src/controller/email.js Normal file
View file

@ -0,0 +1,31 @@
class EmailController {
constructor(mailer, config) {
this.mailer = mailer;
this.config = config;
}
async sendPasswordReset(params = {}) {
const { address, username, url } = params;
const resetConfig = this.config.getPasswordReset();
const html = resetConfig.getHTML()
.replace(/\$user\$/g, username)
.replace(/\$url\$/g, url);
const text = resetConfig.getText()
.replace(/\$user\$/g, username)
.replace(/\$url\$/g, url);
const result = await this.mailer.sendMail({
from: resetConfig.getFrom(),
to: `${username} <${address}>`,
subject: resetConfig.getSubject(),
html,
text
});
return result;
}
}
export { EmailController };