ForgeTotal.js 5
it

Total.js 5

Invia a te stesso un messaggio con LOGMAIL()

Total.js 5 · total5@0.0.19 mailsmtplogging Eseguita con Total.js 5

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.

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