diff --git a/server/server.js b/server/server.js index cb7ae9a..8afa87b 100644 --- a/server/server.js +++ b/server/server.js @@ -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: '
If you received this, email delivery is working correctly.
', + 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 ─────────────────────────────────────────────── app.get('/api/setup/status', async (req, res) => {