This npm module is a wrapper around the
sendgrid module meant for quick and
easy email/alert sending.
npm install --save email-alerts
options: An object that can have the following fields specified:
fromEmail: optional, allows you to customize the email domain that you will receive alerts from if you want to filter the emails.
toEmail: required, specifies the email that alerts will be sent to.
apiKey: required, specifies the Sendgrid API Key. Obtain one here. (You get 100k emails free).
subject: optional, allows you to specify the subject header of any alert email.
An email-alerts object that you can use to call the following methods.
var emailAlerts =fromEmail: 'firstname.lastname@example.org'toEmail: 'email@example.com'apiKey: 'YOUR_KEY_HERE'subject: 'ALERT HOLY S***';
It is recommended to store your SendGrid API key in an environment variable
and pass it using
Sends an email to with the given subject and content, with a callback to be called when the email is finished being sent.
subject: the subject header of the email. Cannot be falsy.
content: the body content of the email. Cannot be falsy.
callback: the function to be called after the email is sent. Generally of the form
Wraps a function with a
try...catch that will send an email if an exception
fn: the function to be executed.
[onError]: the function to be run if an exception was caught while running
fn. The caught exception will be passed to this function.
emailAlerts;// If someFn errors during execution, then an alert email will be sent.emailAlerts;// If someFn errors during execution, then an alert email will be sent.// doSomethingWith(error) will be executed with the error that was caught// during the execution of someFn.emailAlerts;// In this case, an alert email containing 'donald trump is running for// president' will be sent to you, and then it will be logged to the console.
Returns a function that can be passed as a error callback. If no callback was specified, then the function returned will take one argument, an error. If a callback was specified, then this will wrap the callback with a handler that sends an email if there was an error.
[callback]: optional, a callback that will be wrapped by the error handler. Generally of the form
A callback function that can be used as an error callback.
;// If asynchronousFn1 passes an error to the errorHandler, then an alert email// will be sent containing that error.;// If asynchronousFn2 passes an error to the errorHandler, then an alert email// will be sent in addition to it being logged in the console. If no error was// passed, then everything will proceed as normal and the data will be// processed.