|
@@ -16,30 +16,22 @@
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
*/
|
|
-const { AdvancedBase } = require("@heyputer/puter-js-common");
|
|
|
|
|
|
|
|
-class Emailservice extends AdvancedBase {
|
|
|
|
- static MODULES = {
|
|
|
|
- nodemailer: require('nodemailer'),
|
|
|
|
- handlebars: require('handlebars'),
|
|
|
|
- };
|
|
|
|
|
|
+const BaseService = require('./BaseService');
|
|
|
|
|
|
- constructor ({ services, config }) {
|
|
|
|
- super();
|
|
|
|
- this.config = config;
|
|
|
|
-
|
|
|
|
- this.templates = {
|
|
|
|
- 'new-referral': {
|
|
|
|
- subject: `You've made a referral!`,
|
|
|
|
- html: `<p>Hi there,</p>
|
|
|
|
- <p>A new user has used your referral code. Enjoy an extra {{storage_increase}} of storage, on the house!</p>
|
|
|
|
- <p>Sincerely,</p>
|
|
|
|
- <p>Puter</p>
|
|
|
|
- `,
|
|
|
|
- },
|
|
|
|
- 'approved-for-listing': {
|
|
|
|
- subject: '\u{1f389} Your app has been approved for listing!',
|
|
|
|
- html: `
|
|
|
|
|
|
+const TEMPLATES = {
|
|
|
|
+ 'new-referral': {
|
|
|
|
+ subject: `You've made a referral!`,
|
|
|
|
+ html: `
|
|
|
|
+ <p>Hi there,</p>
|
|
|
|
+ <p>A new user has used your referral code. Enjoy an extra {{storage_increase}} of storage, on the house!</p>
|
|
|
|
+ <p>Sincerely,</p>
|
|
|
|
+ <p>Puter</p>
|
|
|
|
+ `,
|
|
|
|
+ },
|
|
|
|
+ 'approved-for-listing': {
|
|
|
|
+ subject: '\u{1f389} Your app has been approved for listing!',
|
|
|
|
+ html: `
|
|
<p>Hi there,</p>
|
|
<p>Hi there,</p>
|
|
<p>
|
|
<p>
|
|
Exciting news! <a href="https://puter.com/app/{{app_name}}">{{app_title}}</a> is now approved and live on <a href="https://puter.com/app/app-center" target="_blank">Puter App Center</a>. It's now ready for users worldwide to discover and enjoy.
|
|
Exciting news! <a href="https://puter.com/app/{{app_name}}">{{app_title}}</a> is now approved and live on <a href="https://puter.com/app/app-center" target="_blank">Puter App Center</a>. It's now ready for users worldwide to discover and enjoy.
|
|
@@ -51,11 +43,11 @@ Exciting news! <a href="https://puter.com/app/{{app_name}}">{{app_title}}</a> is
|
|
<p>Best,<br />
|
|
<p>Best,<br />
|
|
The Puter Team
|
|
The Puter Team
|
|
</p>
|
|
</p>
|
|
- `,
|
|
|
|
- },
|
|
|
|
- 'email_change_request': {
|
|
|
|
- subject: '\u{1f4dd} Confirm your email change',
|
|
|
|
- html: `
|
|
|
|
|
|
+ `,
|
|
|
|
+ },
|
|
|
|
+ 'email_change_request': {
|
|
|
|
+ subject: '\u{1f4dd} Confirm your email change',
|
|
|
|
+ html: `
|
|
<p>Hi there,</p>
|
|
<p>Hi there,</p>
|
|
<p>
|
|
<p>
|
|
We received a request to link this email to the user "{{username}}" on Puter. If you made this request, please click the link below to confirm the change. If you did not make this request, please ignore this email.
|
|
We received a request to link this email to the user "{{username}}" on Puter. If you made this request, please click the link below to confirm the change. If you did not make this request, please ignore this email.
|
|
@@ -64,59 +56,110 @@ We received a request to link this email to the user "{{username}}" on Puter. If
|
|
<p>
|
|
<p>
|
|
<a href="{{confirm_url}}">Confirm email change</a>
|
|
<a href="{{confirm_url}}">Confirm email change</a>
|
|
</p>
|
|
</p>
|
|
- `,
|
|
|
|
- },
|
|
|
|
- 'email_change_notification': {
|
|
|
|
- subject: '\u{1f4dd} Notification of email change',
|
|
|
|
- html: `
|
|
|
|
|
|
+ `,
|
|
|
|
+ },
|
|
|
|
+ 'email_change_notification': {
|
|
|
|
+ subject: '\u{1f4dd} Notification of email change',
|
|
|
|
+ html: `
|
|
<p>Hi there,</p>
|
|
<p>Hi there,</p>
|
|
<p>
|
|
<p>
|
|
We're sending an email to let you know about a change to your account.
|
|
We're sending an email to let you know about a change to your account.
|
|
We have sent a confirmation to "{{new_email}}" to confirm an email change request.
|
|
We have sent a confirmation to "{{new_email}}" to confirm an email change request.
|
|
If this was not you, please contact support@puter.com immediately.
|
|
If this was not you, please contact support@puter.com immediately.
|
|
</p>
|
|
</p>
|
|
- `,
|
|
|
|
- },
|
|
|
|
- };
|
|
|
|
|
|
+ `,
|
|
|
|
+ },
|
|
|
|
+ 'email_verification_code': {
|
|
|
|
+ subject: `{{code}} is your confirmation code`,
|
|
|
|
+ html: /*html*/`
|
|
|
|
+ <p>Hi there,</p>
|
|
|
|
+ <p><strong>{{code}}</strong> is your email confirmation code.</p>
|
|
|
|
+ <p>Sincerely,</p>
|
|
|
|
+ <p>Puter</p>
|
|
|
|
+ `
|
|
|
|
+ },
|
|
|
|
+ 'email_verification_link': {
|
|
|
|
+ subject: `Please confirm your email`,
|
|
|
|
+ html: /*html*/`
|
|
|
|
+ <p>Hi there,</p>
|
|
|
|
+ <p>Please confirm your email address using this link: <strong><a href="{{link}}">{{link}}</a></strong>.</p>
|
|
|
|
+ <p>Sincerely,</p>
|
|
|
|
+ <p>Puter</p>
|
|
|
|
+ `
|
|
|
|
+ },
|
|
|
|
+ 'email_password_recovery': {
|
|
|
|
+ subject: `Password Recovery`,
|
|
|
|
+ html: /*html*/`
|
|
|
|
+ <p>Hi there,</p>
|
|
|
|
+ <p>A password recovery request was issued for your account, please follow the link below to reset your password:</p>
|
|
|
|
+ <p><a href="{{link}}">{{link}}</a></p>
|
|
|
|
+ <p>Sincerely,</p>
|
|
|
|
+ <p>Puter</p>
|
|
|
|
+ `,
|
|
|
|
+ },
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+class Emailservice extends BaseService {
|
|
|
|
+ static MODULES = {
|
|
|
|
+ nodemailer: require('nodemailer'),
|
|
|
|
+ handlebars: require('handlebars'),
|
|
|
|
+ dedent: require('dedent'),
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ _construct () {
|
|
|
|
+ this.templates = TEMPLATES;
|
|
|
|
|
|
this.template_fns = {};
|
|
this.template_fns = {};
|
|
for ( const k in this.templates ) {
|
|
for ( const k in this.templates ) {
|
|
const template = this.templates[k];
|
|
const template = this.templates[k];
|
|
this.template_fns[k] = values => {
|
|
this.template_fns[k] = values => {
|
|
- const html = this.modules.handlebars.compile(template.html);
|
|
|
|
|
|
+ const subject = this.modules.handlebars.compile(template.subject);
|
|
|
|
+ const html =
|
|
|
|
+ this.modules.handlebars.compile(
|
|
|
|
+ this.modules.dedent(template.html));
|
|
return {
|
|
return {
|
|
...template,
|
|
...template,
|
|
|
|
+ subject: subject(values),
|
|
html: html(values),
|
|
html: html(values),
|
|
};
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- async send_email (user, template, values) {
|
|
|
|
- const config = this.config;
|
|
|
|
|
|
+ _init () {
|
|
|
|
+ console.log('the config', this.config);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ get_transport_ () {
|
|
const nodemailer = this.modules.nodemailer;
|
|
const nodemailer = this.modules.nodemailer;
|
|
|
|
|
|
- let transporter = nodemailer.createTransport({
|
|
|
|
- host: config.smtp_server,
|
|
|
|
- port: config.smpt_port,
|
|
|
|
- secure: true, // STARTTLS
|
|
|
|
- auth: {
|
|
|
|
- user: config.smtp_username,
|
|
|
|
- pass: config.smtp_password,
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
|
|
+ const config = { ...this.config };
|
|
|
|
+ delete config.engine;
|
|
|
|
+
|
|
|
|
+ let transport = nodemailer.createTransport(config);
|
|
|
|
|
|
|
|
+ return transport;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async send_email (user, template, values) {
|
|
const email = user.email;
|
|
const email = user.email;
|
|
|
|
|
|
const template_fn = this.template_fns[template];
|
|
const template_fn = this.template_fns[template];
|
|
const { subject, html } = template_fn(values);
|
|
const { subject, html } = template_fn(values);
|
|
|
|
|
|
|
|
+ const transporter = this.get_transport_();
|
|
transporter.sendMail({
|
|
transporter.sendMail({
|
|
from: '"Puter" no-reply@puter.com', // sender address
|
|
from: '"Puter" no-reply@puter.com', // sender address
|
|
to: email, // list of receivers
|
|
to: email, // list of receivers
|
|
subject, html,
|
|
subject, html,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // simple passthrough to nodemailer
|
|
|
|
+ sendMail (params) {
|
|
|
|
+ const transporter = this.get_transport_();
|
|
|
|
+ transporter.sendMail(params);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
module.exports = {
|