# Mail yourself a message with LOGMAIL()

> Send a plain text or JSON message to an address without a view, for logs and alerts, through the same SMTP settings as MAIL().

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

`LOGMAIL(email, [subject], body, [callback])` sends a message made for the developer, not for a customer: no view, no layout. The body is a text. The text goes inside a `<pre>`, in a small HTML page, so line breaks and spaces survive; it is put as it is, so do not send untrusted HTML. Without a `subject` the subject is the name of the application (`name` in the `config`).

**Pass the body as a text.** For an object use `JSON.stringify(object, null, 2)`, as the second route below does.

It uses the same SMTP server, sender and queue as `MAIL()` (`mail_smtp`, `mail_smtp_options`, `mail_from` in the `config`). It is meant for things like "the import failed" with the data that you need to see.

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