# Wyślij sobie wiadomość przez LOGMAIL()

> Wyślij zwykły tekst lub JSON na adres bez widoku, do logów i alertów, przez te same ustawienia SMTP co MAIL().

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

`LOGMAIL(email, [subject], body, [callback])` wysyła wiadomość przeznaczoną dla programisty, nie dla klienta: bez widoku i layoutu. Treść to tekst. Tekst trafia do `<pre>` w małej stronie HTML, dzięki czemu zachowane są podziały wierszy i spacje; jest wstawiany bez zmian, więc nie wysyłaj niezaufanego HTML. Bez `subject` tematem jest nazwa aplikacji (`name` w `config`).

**Przekaż treść jako tekst.** Dla obiektu użyj `JSON.stringify(object, null, 2)`, tak jak robi to druga trasa poniżej.

Używa tego samego serwera SMTP, nadawcy i kolejki co `MAIL()` (`mail_smtp`, `mail_smtp_options`, `mail_from` w `config`). Jest przeznaczony do spraw typu „import się nie powiódł” z danymi, które musisz zobaczyć.

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