# Invia a te stesso un messaggio con LOGMAIL()

> Invia un messaggio di testo semplice o JSON a un indirizzo senza vista, per log e avvisi, con le stesse impostazioni SMTP di MAIL().

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: it
Content-SHA256: 626d7f39e62207ed2ac4a9b5f41b7824a388e10619e01732e8de2a4ef5fe4b5c
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

`LOGMAIL(email, [subject], body, [callback])` invia un messaggio pensato per lo sviluppatore, non per un cliente: senza vista né layout. Il corpo è un testo. Il testo va dentro un `<pre>`, in una piccola pagina HTML, così gli a capo e gli spazi si conservano; viene inserito così com'è, quindi non inviare HTML non fidato. Senza `subject`, l'oggetto è il nome dell'applicazione (`name` nel `config`).

**Passa il corpo come testo.** Per un oggetto usa `JSON.stringify(object, null, 2)`, come fa la seconda route qui sotto.

Usa lo stesso server SMTP, mittente e coda di `MAIL()` (`mail_smtp`, `mail_smtp_options`, `mail_from` nel `config`). È pensato per cose come «l'importazione è fallita» con i dati che ti servono vedere.

```text config
name : Log mail example
mail_smtp : 127.0.0.1
mail_smtp_options : { port: 2527 }
mail_from : hello@example.com
mail_from_name : Example
```

```js controllers/log.js
exports.install = function() {
	ROUTE('POST /alert/ @json', alert);
	ROUTE('POST /alert-object/ @json', alert_object);
	ROUTE('POST /alert-raw/ @json', alert_raw);
};

function alert($) {
	LOGMAIL('ops@example.com', 'Import failed', 'Line 1\nLine 2', function(err) {
		$.json({ sent: !err, error: err ? err.toString() : null });
	});
}

function alert_object($) {
	// without a subject: the subject is the name of the application; the object is written by us
	LOGMAIL('ops@example.com', JSON.stringify({ rows: 12, failed: ['a', 'b'] }, null, 2), function(err) {
		$.json({ sent: !err, error: err ? err.toString() : null });
	});
}

function alert_raw($) {
	// the object itself: it throws in total5 0.0.19
	try {
		LOGMAIL('ops@example.com', { rows: 12 }, NOOP);
		$.json({ thrown: false });
	} catch (e) {
		$.json({ thrown: true, error: e.message });
	}
}
```
