# Stuur jezelf een bericht met LOGMAIL()

> Stuur een gewone tekst of JSON naar een adres zonder view, voor logs en meldingen, via dezelfde SMTP-instellingen als MAIL().

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

`LOGMAIL(email, [subject], body, [callback])` verstuurt een bericht voor de ontwikkelaar, niet voor een klant: geen view, geen layout. De body is een tekst. De tekst komt in een `<pre>` in een kleine HTML-pagina, zodat regeleinden en spaties behouden blijven; hij wordt ongewijzigd geplaatst, dus stuur geen onbetrouwbare HTML. Zonder `subject` is het onderwerp de naam van de applicatie (`name` in de `config`).

**Geef de body als tekst door.** Gebruik voor een object `JSON.stringify(object, null, 2)`, zoals de tweede route hieronder doet.

Het gebruikt dezelfde SMTP-server, afzender en wachtrij als `MAIL()` (`mail_smtp`, `mail_smtp_options`, `mail_from` in de `config`). Het is bedoeld voor zaken als "de import is mislukt" met de gegevens die je moet zien.

```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 });
	}
}
```
