Start working on nodemailer upgrade
This commit is contained in:
parent
071def0838
commit
9cfe71d4c4
4 changed files with 111 additions and 1 deletions
29
src/configuration/emailconfig.js
Normal file
29
src/configuration/emailconfig.js
Normal 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
31
src/controller/email.js
Normal 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 };
|
||||
Loading…
Add table
Add a link
Reference in a new issue