ForgeTotal.js 5
sk

Total.js 5

Pošlite si správu cez LOGMAIL()

Total.js 5 · total5@0.0.19 mailsmtplogging Spustené s Total.js 5

LOGMAIL(email, [subject], body, [callback]) odošle správu určenú pre vývojára, nie pre zákazníka: bez šablóny a layoutu. Telo je text. Text ide do pre v malej HTML stránke, takže zalomenia riadkov a medzery zostanú zachované; vloží sa tak, ako je, preto neposielajte nedôveryhodné HTML. Bez subject je predmetom názov aplikácie (name v config).

Telo odovzdajte ako text. Pre objekt použite JSON.stringify(object, null, 2), ako to robí druhá cesta nižšie.

Používa rovnaký SMTP server, odosielateľa a frontu ako MAIL() (mail_smtp, mail_smtp_options, mail_from v config). Je určený pre veci ako „import zlyhal“ s dátami, ktoré potrebujete vidieť.

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