Deliverability: Message-ID allineato al dominio mittente + checklist dominio
- trySend(): genera un Message-ID nel dominio del From (il default di nodemailer usa l'hostname del container -> dominio incoerente, segnale antispam). - CHECKLIST-COMPLIANCE-MERCHANT: l'autenticazione del dominio mittente (SPF/DKIM/ DMARC) e la configurazione SMTP diventano obblighi espliciti del merchant; senza, la ricevuta durevole non raggiunge il consumatore. Chiarito che l'app la invia sempre ma la consegna dipende dal provider/dominio del merchant.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
* SMTP_SECURE("true"/"false"), MAIL_FROM. DEV: Mailpit localhost:1025.
|
||||
*/
|
||||
|
||||
import { randomUUID } from "node:crypto";
|
||||
import nodemailer from "nodemailer";
|
||||
import {
|
||||
renderReceiptHtml,
|
||||
@@ -66,16 +67,28 @@ function mailFrom(smtp?: SmtpConfig | null): string {
|
||||
|
||||
type Transport = NonNullable<ReturnType<typeof buildTransport>>;
|
||||
|
||||
/**
|
||||
* Message-ID allineato al dominio del mittente. Un Message-ID con dominio
|
||||
* incoerente (di default: l'hostname del container) e' un segnale negativo
|
||||
* per i filtri antispam.
|
||||
*/
|
||||
function makeMessageId(from: unknown): string | undefined {
|
||||
if (typeof from !== "string") return undefined;
|
||||
const m = from.match(/@([^>\s]+)/);
|
||||
return m ? `<${randomUUID()}@${m[1]}>` : undefined;
|
||||
}
|
||||
|
||||
/** Invio con retry (backoff lineare). Riduce le ricevute perse per glitch SMTP. */
|
||||
async function trySend(
|
||||
transport: Transport,
|
||||
message: Parameters<Transport["sendMail"]>[0],
|
||||
attempts = 3,
|
||||
) {
|
||||
const msg = { messageId: makeMessageId(message.from), ...message };
|
||||
let lastErr: unknown;
|
||||
for (let i = 0; i < attempts; i++) {
|
||||
try {
|
||||
return await transport.sendMail(message);
|
||||
return await transport.sendMail(msg);
|
||||
} catch (e) {
|
||||
lastErr = e;
|
||||
if (i < attempts - 1) {
|
||||
|
||||
Reference in New Issue
Block a user