Compare commits

1 Commits

Author SHA1 Message Date
fahed 04c420d255 fix: add test-email endpoint for SMTP diagnostics
Deploy / deploy (push) Successful in 12s
POST /api/admin/test-email — superadmin only, returns exact SMTP
host/port/error so we can diagnose why notifications aren't delivered.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 13:30:20 +03:00
+22
View File
@@ -640,6 +640,28 @@ app.get('/api/health', async (req, res) => {
}); });
}); });
// ─── EMAIL TEST ─────────────────────────────────────────────────
app.post('/api/admin/test-email', requireAuth, async (req, res) => {
if (req.session.userRole !== 'superadmin') return res.status(403).json({ error: 'Superadmin only' });
const to = req.body.to || req.session.userEmail;
if (!to) return res.status(400).json({ error: 'No recipient — pass { "to": "email@example.com" }' });
const { sendMail, getSmtpConfig } = require('./mail');
const config = getSmtpConfig();
if (!config) return res.status(503).json({ error: 'SMTP not configured', env: { server: !!process.env.CLOUDRON_MAIL_SMTP_SERVER || !!process.env.MAIL_SMTP_SERVER } });
try {
const info = await sendMail({
to,
subject: 'Rawaj — Test Email',
html: '<p>If you received this, email delivery is working correctly.</p>',
text: 'If you received this, email delivery is working correctly.',
});
res.json({ success: true, to, messageId: info?.messageId, smtp: { host: config.host, port: config.port, from: config.from } });
} catch (err) {
res.status(500).json({ success: false, error: err.message, code: err.code, smtp: { host: config.host, port: config.port } });
}
});
// ─── SETUP ROUTES ─────────────────────────────────────────────── // ─── SETUP ROUTES ───────────────────────────────────────────────
app.get('/api/setup/status', async (req, res) => { app.get('/api/setup/status', async (req, res) => {