Envie uma mensagem a si próprio com LOGMAIL()
LOGMAIL(email, [subject], body, [callback]) envia uma mensagem feita para o programador, não para um cliente: sem vista nem layout. O corpo é um texto. O texto vai dentro de um pre, numa pequena página HTML, de modo que as quebras de linha e os espaços se mantêm; é colocado tal como está, por isso não envie HTML não confiável. Sem subject, o assunto é o nome da aplicação (name no config).
Passe o corpo como texto. Para um objeto use JSON.stringify(object, null, 2), como faz a segunda rota abaixo.
Usa o mesmo servidor SMTP, remetente e fila que MAIL() (mail_smtp, mail_smtp_options, mail_from no config). Destina-se a coisas como «a importação falhou» com os dados que precisa de ver.
name : Log mail example
mail_smtp : 127.0.0.1
mail_smtp_options : { port: 2527 }
mail_from : hello@example.com
mail_from_name : Exampleexports.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 });
}
}