email_server/s1.js
2025-12-07 16:57:53 +01:00

47 lines
1.2 KiB
JavaScript

const express = require('express');
const bodyParser = require('body-parser');
const nodemailer = require('nodemailer');
const app = express();
app.use(bodyParser.json());
// Configura il trasporto SMTP per IONOS
const transporter = nodemailer.createTransport({
host: 'smtp.ionos.it', // usa .com se il tuo dominio è internazionale
port: 587, // oppure 465 per SSL
secure: false, // true solo se usi 465
auth: {
user: 'admin@patachina.it',
pass: 'EmailMaster6691!!'
}
});
// Endpoint per inviare email
app.post('/send-email', async (req, res) => {
const { to, subject, text, html } = req.body;
if (!to || !subject || (!text && !html)) {
return res.status(400).json({ error: 'Parametri mancanti: to, subject, text/html' });
}
try {
const info = await transporter.sendMail({
from: 'admin@patachina.it',
to,
subject,
text,
html
});
res.json({ message: 'Email inviata con successo!', info });
} catch (error) {
console.error('Errore invio email:', error);
res.status(500).json({ error: 'Errore durante l\'invio dell\'email', details: error.message });
}
});
// Avvia il server
const PORT = 3400;
app.listen(PORT, () => {
console.log(`Server attivo su http://192.168.1.3:${PORT}`);
});