Skicka ett meddelande till dig själv med LOGMAIL()
LOGMAIL(email, [subject], body, [callback]) skickar ett meddelande avsett för utvecklaren, inte för en kund: ingen vy, ingen layout. Innehållet är en text. Texten hamnar i en pre på en liten HTML-sida, så radbrytningar och mellanslag bevaras; den sätts in som den är, så skicka inte opålitlig HTML. Utan subject är ämnet applikationens namn (name i config).
Skicka innehållet som text. För ett objekt använd JSON.stringify(object, null, 2), som den andra rutten nedan gör.
Den använder samma SMTP-server, avsändare och kö som MAIL() (mail_smtp, mail_smtp_options, mail_from i config). Den är tänkt för saker som "importen misslyckades" med de data du behöver se.
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 });
}
}