Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
import assert from 'node:assert';
|
|
|
|
|
import BoxError from './boxerror.js';
|
2026-02-14 15:43:24 +01:00
|
|
|
import branding from './branding.js';
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
import constants from './constants.js';
|
2026-02-14 15:43:24 +01:00
|
|
|
import dashboard from './dashboard.js';
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
import debugModule from 'debug';
|
|
|
|
|
import ejs from 'ejs';
|
2026-02-14 15:43:24 +01:00
|
|
|
import mailServer from './mailserver.js';
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
import nodemailer from 'nodemailer';
|
|
|
|
|
import path from 'node:path';
|
|
|
|
|
import safe from 'safetydance';
|
2026-02-14 15:43:24 +01:00
|
|
|
import translations from './translations.js';
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
|
|
|
|
|
const debug = debugModule('box:mailer');
|
|
|
|
|
|
|
|
|
|
const _mailQueue = []; // accumulate mails in test mode;
|
|
|
|
|
|
|
|
|
|
function clearMailQueue() {
|
|
|
|
|
_mailQueue.length = 0;
|
|
|
|
|
}
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
const MAIL_TEMPLATES_DIR = path.join(import.meta.dirname, 'mail_templates');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
// This will collect the most common details required for notification emails
|
2021-08-19 12:32:23 -07:00
|
|
|
async function getMailConfig() {
|
2023-08-02 21:01:11 +05:30
|
|
|
const cloudronName = await branding.getCloudronName();
|
2024-12-11 18:24:20 +01:00
|
|
|
const { fqdn:dashboardFqdn, domain:dashboardDomain } = await dashboard.getLocation();
|
2021-08-19 12:32:23 -07:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
cloudronName,
|
2023-08-11 19:41:05 +05:30
|
|
|
notificationFrom: `"${cloudronName}" <no-reply@${dashboardDomain}>`,
|
2024-12-11 18:24:20 +01:00
|
|
|
supportEmail: 'support@cloudron.io',
|
2024-12-11 20:44:46 +01:00
|
|
|
dashboardFqdn,
|
|
|
|
|
notificationsUrl: `https://${dashboardFqdn}/cloudron/#/notifications`
|
2021-08-19 12:32:23 -07:00
|
|
|
};
|
2016-09-03 12:02:42 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
async function sendMail(mailOptions) {
|
2019-04-15 16:36:37 -07:00
|
|
|
assert.strictEqual(typeof mailOptions, 'object');
|
2015-11-10 00:24:40 -08:00
|
|
|
|
2023-10-01 13:52:19 +05:30
|
|
|
if (constants.TEST) {
|
Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
(dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing
Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 09:53:14 +01:00
|
|
|
_mailQueue.push(mailOptions);
|
2021-08-19 12:32:23 -07:00
|
|
|
return;
|
2019-04-15 16:36:37 -07:00
|
|
|
}
|
|
|
|
|
|
2023-08-11 19:41:05 +05:30
|
|
|
const { domain:dashboardDomain } = await dashboard.getLocation();
|
2023-08-04 20:54:16 +05:30
|
|
|
const data = await mailServer.getMailAuth();
|
2021-08-19 12:32:23 -07:00
|
|
|
|
2022-09-14 17:41:01 +02:00
|
|
|
const transport = nodemailer.createTransport({
|
2021-08-19 12:32:23 -07:00
|
|
|
host: data.ip,
|
|
|
|
|
port: data.port,
|
|
|
|
|
auth: {
|
2023-08-11 19:41:05 +05:30
|
|
|
user: mailOptions.authUser || `no-reply@${dashboardDomain}`,
|
2021-08-19 12:32:23 -07:00
|
|
|
pass: data.relayToken
|
2025-08-06 09:55:53 +02:00
|
|
|
},
|
2025-08-06 10:00:56 +02:00
|
|
|
connectionTimeout: 3000,
|
|
|
|
|
greetingTimeout: 3000,
|
|
|
|
|
socketTimeout: 3000,
|
2025-08-06 09:55:53 +02:00
|
|
|
logger: false,
|
|
|
|
|
debug: false // set to true for smtp logs
|
2022-09-14 17:41:01 +02:00
|
|
|
});
|
2021-08-19 12:32:23 -07:00
|
|
|
|
2025-08-06 08:26:57 +02:00
|
|
|
const [error] = await safe(transport.sendMail(mailOptions));
|
2025-08-06 10:18:05 +02:00
|
|
|
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, `Error sending Email "${mailOptions.subject}" to ${mailOptions.to}: ${error.message}`);
|
|
|
|
|
debug(`Email "${mailOptions.subject}" sent to ${mailOptions.to}`);
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-19 23:38:59 +01:00
|
|
|
function render(templateFile, params, translationAssets) {
|
2015-07-20 00:09:47 -07:00
|
|
|
assert.strictEqual(typeof templateFile, 'string');
|
|
|
|
|
assert.strictEqual(typeof params, 'object');
|
|
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
let content = null;
|
|
|
|
|
let raw = safe.fs.readFileSync(path.join(MAIL_TEMPLATES_DIR, templateFile), 'utf8');
|
2020-11-19 23:38:59 +01:00
|
|
|
if (raw === null) {
|
|
|
|
|
debug(`Error loading ${templateFile}`);
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-05 12:45:23 +02:00
|
|
|
if (typeof translationAssets === 'object') raw = translations.translate(raw, translationAssets);
|
2017-08-04 12:02:50 +02:00
|
|
|
|
|
|
|
|
try {
|
2020-11-19 23:38:59 +01:00
|
|
|
content = ejs.render(raw, params);
|
2017-08-04 12:02:50 +02:00
|
|
|
} catch (e) {
|
2017-08-04 11:15:55 -07:00
|
|
|
debug(`Error rendering ${templateFile}`, e);
|
2017-08-04 12:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return content;
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2021-10-27 19:58:06 +02:00
|
|
|
async function sendInvite(user, invitor, email, inviteLink) {
|
2015-07-20 00:09:47 -07:00
|
|
|
assert.strictEqual(typeof user, 'object');
|
2020-02-05 15:53:05 +01:00
|
|
|
assert.strictEqual(typeof invitor, 'object');
|
2021-10-27 21:25:43 +02:00
|
|
|
assert.strictEqual(typeof email, 'string');
|
2020-02-05 15:53:05 +01:00
|
|
|
assert.strictEqual(typeof inviteLink, 'string');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
const mailConfig = await getMailConfig();
|
2024-07-05 12:45:23 +02:00
|
|
|
const translationAssets = await translations.getTranslations();
|
2021-08-19 12:32:23 -07:00
|
|
|
|
|
|
|
|
const templateData = {
|
|
|
|
|
user: user.displayName || user.username || user.email,
|
2024-12-11 18:24:20 +01:00
|
|
|
webadminUrl: `https://${mailConfig.dashboardFqdn}`,
|
2021-08-19 12:32:23 -07:00
|
|
|
inviteLink: inviteLink,
|
|
|
|
|
invitor: invitor ? invitor.email : null,
|
|
|
|
|
cloudronName: mailConfig.cloudronName,
|
2024-12-11 18:24:20 +01:00
|
|
|
cloudronAvatarUrl: `https://${mailConfig.dashboardFqdn}/api/v1/cloudron/avatar`
|
2021-08-19 12:32:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
2021-10-27 19:58:06 +02:00
|
|
|
to: email,
|
2024-07-05 12:45:23 +02:00
|
|
|
subject: ejs.render(translations.translate('{{ welcomeEmail.subject }}', translationAssets), { cloudron: mailConfig.cloudronName }),
|
2021-08-19 12:32:23 -07:00
|
|
|
text: render('welcome_user-text.ejs', templateData, translationAssets),
|
|
|
|
|
html: render('welcome_user-html.ejs', templateData, translationAssets)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await sendMail(mailOptions);
|
2016-01-18 16:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
async function sendNewLoginLocation(user, loginLocation) {
|
2021-04-21 15:57:12 +02:00
|
|
|
assert.strictEqual(typeof user, 'object');
|
2021-04-30 11:32:15 -07:00
|
|
|
assert.strictEqual(typeof loginLocation, 'object');
|
|
|
|
|
|
|
|
|
|
const { ip, userAgent, country, city } = loginLocation;
|
|
|
|
|
|
2021-04-30 13:21:50 +02:00
|
|
|
assert.strictEqual(typeof ip, 'string');
|
|
|
|
|
assert.strictEqual(typeof userAgent, 'string');
|
|
|
|
|
assert.strictEqual(typeof country, 'string');
|
|
|
|
|
assert.strictEqual(typeof city, 'string');
|
2021-04-21 15:57:12 +02:00
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
const mailConfig = await getMailConfig();
|
2024-07-05 12:45:23 +02:00
|
|
|
const translationAssets = await translations.getTranslations();
|
2021-08-19 12:32:23 -07:00
|
|
|
|
|
|
|
|
const templateData = {
|
|
|
|
|
user: user.displayName || user.username || user.email,
|
|
|
|
|
ip,
|
|
|
|
|
userAgent: userAgent || 'unknown',
|
|
|
|
|
country,
|
|
|
|
|
city,
|
|
|
|
|
cloudronName: mailConfig.cloudronName,
|
2024-12-11 18:24:20 +01:00
|
|
|
cloudronAvatarUrl: `https://${mailConfig.dashboardFqdn}/api/v1/cloudron/avatar`
|
2021-08-19 12:32:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
2021-11-17 11:53:03 -08:00
|
|
|
to: user.email,
|
2024-07-05 12:45:23 +02:00
|
|
|
subject: ejs.render(translations.translate('{{ newLoginEmail.subject }}', translationAssets), { cloudron: mailConfig.cloudronName }),
|
2021-08-19 12:32:23 -07:00
|
|
|
text: render('new_login_location-text.ejs', templateData, translationAssets),
|
|
|
|
|
html: render('new_login_location-html.ejs', templateData, translationAssets)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await sendMail(mailOptions);
|
2021-04-21 15:57:12 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-27 18:36:28 +02:00
|
|
|
async function passwordReset(user, email, resetLink) {
|
2015-07-20 00:09:47 -07:00
|
|
|
assert.strictEqual(typeof user, 'object');
|
2021-10-27 18:36:28 +02:00
|
|
|
assert.strictEqual(typeof email, 'string');
|
|
|
|
|
assert.strictEqual(typeof resetLink, 'string');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
const mailConfig = await getMailConfig();
|
2024-07-05 12:45:23 +02:00
|
|
|
const translationAssets = await translations.getTranslations();
|
2021-08-19 12:32:23 -07:00
|
|
|
|
|
|
|
|
const templateData = {
|
|
|
|
|
user: user.displayName || user.username || user.email,
|
2021-09-16 14:34:56 +02:00
|
|
|
resetLink: resetLink,
|
2021-08-19 12:32:23 -07:00
|
|
|
cloudronName: mailConfig.cloudronName,
|
2024-12-11 18:24:20 +01:00
|
|
|
cloudronAvatarUrl: `https://${mailConfig.dashboardFqdn}/api/v1/cloudron/avatar`
|
2021-08-19 12:32:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
2021-10-27 18:36:28 +02:00
|
|
|
to: email,
|
2024-07-05 12:45:23 +02:00
|
|
|
subject: ejs.render(translations.translate('{{ passwordResetEmail.subject }}', translationAssets), { cloudron: mailConfig.cloudronName }),
|
2021-08-19 12:32:23 -07:00
|
|
|
text: render('password_reset-text.ejs', templateData, translationAssets),
|
|
|
|
|
html: render('password_reset-html.ejs', templateData, translationAssets)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await sendMail(mailOptions);
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2024-12-11 20:44:46 +01:00
|
|
|
async function appDown(mailTo, app) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
|
|
|
|
assert.strictEqual(typeof app, 'object');
|
|
|
|
|
|
|
|
|
|
const mailConfig = await getMailConfig();
|
|
|
|
|
|
|
|
|
|
const mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
|
|
|
|
subject: `[${mailConfig.cloudronName}] App ${app.fqdn} is down`,
|
2024-12-11 23:32:11 +01:00
|
|
|
text: render('app_down-text.ejs', { title: app.manifest.title, appFqdn: app.fqdn, notificationsUrl: mailConfig.notificationsUrl })
|
2024-12-11 20:44:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await sendMail(mailOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function appUp(mailTo, app) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
|
|
|
|
assert.strictEqual(typeof app, 'object');
|
|
|
|
|
|
|
|
|
|
const mailConfig = await getMailConfig();
|
|
|
|
|
|
|
|
|
|
const mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
|
|
|
|
subject: `[${mailConfig.cloudronName}] App ${app.fqdn} is back online`,
|
2024-12-11 23:32:11 +01:00
|
|
|
text: render('app_up-text.ejs', { title: app.manifest.title, appFqdn: app.fqdn, notificationsUrl: mailConfig.notificationsUrl })
|
2024-12-11 20:44:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await sendMail(mailOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 23:32:11 +01:00
|
|
|
async function oomEvent(mailTo, containerId, app, addon, event) {
|
2024-12-11 20:44:46 +01:00
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
2024-12-11 23:32:11 +01:00
|
|
|
assert.strictEqual(typeof containerId, 'string');
|
2024-12-11 20:44:46 +01:00
|
|
|
assert.strictEqual(typeof app, 'object');
|
|
|
|
|
assert.strictEqual(typeof addon, 'object');
|
|
|
|
|
assert.strictEqual(typeof event, 'object');
|
|
|
|
|
|
|
|
|
|
const mailConfig = await getMailConfig();
|
|
|
|
|
|
|
|
|
|
const templateData = {
|
|
|
|
|
webadminUrl: `https://${mailConfig.dashboardFqdn}`,
|
|
|
|
|
cloudronName: mailConfig.cloudronName,
|
|
|
|
|
app,
|
|
|
|
|
addon,
|
|
|
|
|
event: JSON.stringify(event),
|
|
|
|
|
notificationsUrl: mailConfig.notificationsUrl
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
|
|
|
|
subject: `[${mailConfig.cloudronName}] ${app ? app.fqdn : addon.name} was restarted (OOM)`,
|
2024-12-11 23:32:11 +01:00
|
|
|
text: render('oom_event-text.ejs', templateData)
|
2024-12-11 20:44:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await sendMail(mailOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
async function backupFailed(mailTo, errorMessage, logUrl) {
|
2019-03-10 15:53:20 -07:00
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
2021-06-24 01:18:27 -07:00
|
|
|
assert.strictEqual(typeof errorMessage, 'string');
|
|
|
|
|
assert.strictEqual(typeof logUrl, 'string');
|
2019-03-10 15:53:20 -07:00
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
const mailConfig = await getMailConfig();
|
2016-10-14 14:46:34 -07:00
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
const mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
|
|
|
|
subject: `[${mailConfig.cloudronName}] Failed to backup`,
|
2024-12-11 23:32:11 +01:00
|
|
|
text: render('backup_failed-text.ejs', { cloudronName: mailConfig.cloudronName, message: errorMessage, logUrl, notificationsUrl: mailConfig.notificationsUrl })
|
2021-08-19 12:32:23 -07:00
|
|
|
};
|
2018-01-19 16:27:19 +01:00
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
await sendMail(mailOptions);
|
2016-10-14 14:46:34 -07:00
|
|
|
}
|
|
|
|
|
|
2025-01-19 10:34:12 +01:00
|
|
|
async function rebootRequired(mailTo) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
|
|
|
|
|
|
|
|
|
const mailConfig = await getMailConfig();
|
|
|
|
|
|
|
|
|
|
const mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
|
|
|
|
subject: `[${mailConfig.cloudronName}] Reboot required for security updates`,
|
|
|
|
|
text: render('reboot_required-text.ejs', { webadminUrl: `https://${mailConfig.dashboardFqdn}`, notificationsUrl: mailConfig.notificationsUrl })
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await sendMail(mailOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-07 13:15:08 +02:00
|
|
|
async function lowDiskSpace(mailTo, message) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
|
|
|
|
assert.strictEqual(typeof message, 'string');
|
|
|
|
|
|
|
|
|
|
const mailConfig = await getMailConfig();
|
|
|
|
|
|
|
|
|
|
const mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
|
|
|
|
subject: `[${mailConfig.cloudronName}] Server is running low on disk space`,
|
|
|
|
|
text: render('low_disk_space-text.ejs', { message, notificationsUrl: mailConfig.notificationsUrl })
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await sendMail(mailOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-24 18:44:12 +01:00
|
|
|
async function boxUpdateError(mailTo, message) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
|
|
|
|
assert.strictEqual(typeof message, 'string');
|
|
|
|
|
|
|
|
|
|
const mailConfig = await getMailConfig();
|
|
|
|
|
|
|
|
|
|
const mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
|
|
|
|
subject: `[${mailConfig.cloudronName}] Cloudron update error`,
|
|
|
|
|
text: render('box_update_error-text.ejs', { message, notificationsUrl: mailConfig.notificationsUrl })
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await sendMail(mailOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
async function certificateRenewalError(mailTo, domain, message) {
|
2019-03-10 15:53:20 -07:00
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
2016-03-19 20:40:03 -07:00
|
|
|
assert.strictEqual(typeof domain, 'string');
|
|
|
|
|
assert.strictEqual(typeof message, 'string');
|
|
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
const mailConfig = await getMailConfig();
|
2016-03-19 20:40:03 -07:00
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
const mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
|
|
|
|
subject: `[${mailConfig.cloudronName}] Certificate renewal error`,
|
2024-12-11 23:32:11 +01:00
|
|
|
text: render('certificate_renewal_error-text.ejs', { domain, message, notificationsUrl: mailConfig.notificationsUrl })
|
2021-08-19 12:32:23 -07:00
|
|
|
};
|
2016-07-26 16:47:58 -07:00
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
await sendMail(mailOptions);
|
2016-03-19 20:40:03 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-22 09:40:06 -07:00
|
|
|
async function sendTestMail(domain, email) {
|
2018-01-23 16:10:23 -08:00
|
|
|
assert.strictEqual(typeof domain, 'string');
|
2017-09-15 14:21:52 +02:00
|
|
|
assert.strictEqual(typeof email, 'string');
|
|
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
const mailConfig = await getMailConfig();
|
2017-09-15 14:21:52 +02:00
|
|
|
|
2021-08-19 12:32:23 -07:00
|
|
|
const mailOptions = {
|
|
|
|
|
authUser: `no-reply@${domain}`,
|
|
|
|
|
from: `"${mailConfig.cloudronName}" <no-reply@${domain}>`,
|
|
|
|
|
to: email,
|
|
|
|
|
subject: `[${mailConfig.cloudronName}] Test Email`,
|
2024-12-11 23:32:11 +01:00
|
|
|
text: render('test-text.ejs', { cloudronName: mailConfig.cloudronName}),
|
2024-07-05 10:30:49 +02:00
|
|
|
html: render('test-html.ejs', { cloudronName: mailConfig.cloudronName })
|
2021-08-19 12:32:23 -07:00
|
|
|
};
|
2018-01-19 16:27:19 +01:00
|
|
|
|
2021-08-22 09:40:06 -07:00
|
|
|
await sendMail(mailOptions);
|
2017-09-15 14:21:52 +02:00
|
|
|
}
|
2026-02-14 15:43:24 +01:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
passwordReset,
|
|
|
|
|
sendInvite,
|
|
|
|
|
sendNewLoginLocation,
|
|
|
|
|
backupFailed,
|
|
|
|
|
certificateRenewalError,
|
|
|
|
|
appDown,
|
|
|
|
|
appUp,
|
|
|
|
|
oomEvent,
|
|
|
|
|
rebootRequired,
|
|
|
|
|
boxUpdateError,
|
|
|
|
|
lowDiskSpace,
|
|
|
|
|
sendTestMail,
|
|
|
|
|
_mailQueue,
|
|
|
|
|
clearMailQueue,
|
|
|
|
|
};
|