Fix invio email: TLS derivato dalla porta (465 diretto / 587 STARTTLS)

Causa reale del mancato invio in prod: Settings aveva porta 587 con 'Connessione
sicura diretta' spuntata -> nodemailer apriva subito TLS su una porta che parla
in chiaro + STARTTLS -> handshake fallito -> receipt_failed.

- buildTransport: secure derivato dalla porta standard (465=true, 587=false),
  requireTLS su 587. Su porte non standard resta la scelta del merchant.
- Checkbox 'Connessione sicura' ora dichiara che e' ignorata sulle porte standard.
- Avviso se notifiche attive ma 'Email notifiche' vuota (era null in prod: per
  questo non arrivava neanche la notifica al merchant).
This commit is contained in:
2026-07-10 09:53:13 +02:00
parent f5d2c8664f
commit 23f6a0a3e8
2 changed files with 16 additions and 2 deletions

View File

@@ -35,13 +35,20 @@ function buildTransport(smtp?: SmtpConfig | null) {
const port = useShop
? Number(smtp!.port ?? 587)
: Number(process.env.SMTP_PORT ?? 587);
const secure = useShop ? !!smtp!.secure : process.env.SMTP_SECURE === "true";
const rawSecure = useShop
? !!smtp!.secure
: process.env.SMTP_SECURE === "true";
// Le porte standard vincolano la modalita' TLS: 465 = TLS diretto, 587 =
// STARTTLS. Spuntare "sicura" sulla 587 (errore comune) rompeva l'handshake.
// Su porte non standard vale la scelta del merchant.
const secure = port === 465 ? true : port === 587 ? false : rawSecure;
const user = useShop ? smtp!.user : process.env.SMTP_USER;
const pass = useShop ? smtp!.pass : process.env.SMTP_PASS;
return nodemailer.createTransport({
host,
port,
secure,
requireTLS: port === 587, // forza STARTTLS dove e' obbligatorio
auth: user ? { user, pass: pass ?? "" } : undefined,
connectionTimeout: 10_000,
greetingTimeout: 10_000,

View File

@@ -439,6 +439,12 @@ export default function SettingsPage() {
helpText="Dove ricevere le notifiche. Senza indirizzo l'email non parte."
placeholder="ordini@tuonegozio.it"
/>
{notifyEnabled && !notifyEmail.trim() ? (
<Banner tone="warning">
Notifiche attive ma nessun indirizzo: al momento non ricevi
nulla. Inserisci un'email.
</Banner>
) : null}
<Checkbox
label="Aggiungi il tag 'Recesso' all'ordine"
checked={tagEnabled}
@@ -616,9 +622,10 @@ export default function SettingsPage() {
}
/>
<Checkbox
label="Connessione sicura diretta (SSL/TLS, porta 465)"
label="Connessione sicura diretta (SSL/TLS)"
checked={smtpSecure}
onChange={setSmtpSecure}
helpText="Ignorato sulle porte standard: 465 usa sempre TLS diretto, 587 usa sempre STARTTLS. Vale solo su porte non standard."
/>
<TextField
label="Mittente (From)"