The small helper for Express that allows you to send email using nodemailer
The typescript support module for Express, that allow you to send an email using Nodemailer in the route handler by calling a certain method from the response object.
# With npmnpm install --save express-nodemailer# With yarnyarn add express-nodemailer
// Declare module;// The parameters that are used as `options` argument for createTransport method of Nodemailer;// The parameters that are used as `defaults` argument for createTransport method of Nodemailer;// Initialize a module to extends your Express applicationexpressNodemailerapp, options, defaults; // `app` is the Express application object// Some Express source code before start server listening...
expressNodemailer extends your Express application by mounting a special middleware to it which implements the ability to send en email by calling the
sandMail method from the response object.
For direct use of the Nodemailer functionality, the
transporter object itself, created with the given arguments, will be available in the Express application object:
Sending an email
Now in your route handler you can send an email by calling
sendMail like this:
This method has four arguments:
sendMail: (to: string, subject: string, text: string, html?: string)
- to - REQUIRED - Comma separated list or an array of recipients email addresses
- subject - REQUIRED - The subject of the e-mail
- text - REQUIRED - The path to template file for text body of email
- html - The path to template file for html body of email
The last two arguments are the paths to the template files that are rendered by same render process as Express. For example, if your Express application use
jade view engine, you should also write your email templates in
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.