-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update dependencies #32
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,6 @@ profile* | |
|
||
# package-lock | ||
package-lock.json | ||
|
||
# node-tap | ||
.tap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
## fastify-mail | ||
# fastify-mail | ||
|
||
A [Fastify](https://www.fastify.io/) plugin that uses [point-of-view](https://github.com/fastify/point-of-view#readme) and [fastify-nodemailer](https://github.com/lependu/fastify-nodemailer#readme) to template and send email messages. | ||
|
||
### Usage | ||
## Usage | ||
|
||
```sh | ||
npm i @autotelic/fastify-mail | ||
``` | ||
|
||
### Setup | ||
## Setup | ||
|
||
`fastify-mail` decorates the reply interface with the `mail` method and takes two options to get started: `pov` and `transporter` | ||
|
||
##### Point-of-View | ||
### Point-of-View | ||
|
||
- `pov.engine` should be a template engine object used to configure point-of-view | ||
- to see a list of engines currently supported by point-of-view with options, [view docs here](https://github.com/fastify/point-of-view/blob/master/index.d.ts) | ||
- For quick start, `fastify-mail` only requires the engine. For example, using `nunjucks`: | ||
|
@@ -23,14 +24,17 @@ npm i @autotelic/fastify-mail | |
|
||
- If you'd prefer to register `point-of-view` on your own, omit the `engine` option and `fastify-mail` will not register it. | ||
- If you configure `point-of-view` with a different decorator name, add this to the options of `fastify-mail` | ||
|
||
```js | ||
fastify.register(mail, { pov: { propertyName: 'POV_DECORATOR' }, transporter: ... }) | ||
``` | ||
|
||
##### Nodemailer | ||
### Nodemailer | ||
|
||
- `transporter` should be an object defining connection data to be used as a `nodemailer` SMTP transport. [View nodemailer's docs here](https://nodemailer.com/smtp/) | ||
- `fastify-mail` decorates `fastify` with `nodemailer` so a transporter must be defined | ||
- For example, using `maildev`: | ||
|
||
```js | ||
const transporter = { | ||
host: 'localhost', | ||
|
@@ -41,7 +45,7 @@ npm i @autotelic/fastify-mail | |
fastify.register(mail, { pov: { engine: ... }, transporter }) | ||
``` | ||
|
||
### Example | ||
## Example | ||
|
||
```js | ||
// index.js | ||
|
@@ -78,69 +82,73 @@ fastify.get("/sendmail", async (req, reply) => { | |
}) | ||
``` | ||
|
||
#### Templates | ||
## Templates | ||
|
||
Each message must have the following templates with the file extension set in point-of-view config: | ||
- 'html': Contains the html template for the email. | ||
- 'text': Contains the text template for the email. | ||
|
||
``` | ||
- 'html': Contains the html template for the email. | ||
- 'text': Contains the text template for the email. | ||
|
||
```sh | ||
. | ||
|--index.js | ||
|--templates | ||
|-- html.njk | ||
|-- text.njk | ||
``` | ||
|
||
#### Example Apps | ||
## Example Apps | ||
|
||
See [/examples/mailgun](./examples/mailgun) for a working example app using [nodemailer-mailgun-transport](https://github.com/xr0master/mailgun-nodemailer-transport#readme). | ||
|
||
See [/examples/maildev](./examples/maildev) for a working example app using [MailDev](https://maildev.github.io/maildev/) | ||
|
||
### API | ||
## API | ||
|
||
#### Decorator | ||
### Decorator | ||
|
||
This plugin decorates fastify with a `mail` object containing the following methods: | ||
|
||
- sendMail: 'function' - Calls `createMessage` to generate an message and uses [fastify-nodemailer](https://github.com/lependu/fastify-nodemailer) to send the generated email. | ||
- Accepts the following arguments: | ||
- message: 'object' | ||
*This is a valid 'message' object as per the Nodemailer API* | ||
- from: 'string' - The email address the email is to be sent from. | ||
- to: 'array' - Comma separated list or an array of recipients email addresses (`string`) that will appear on the To: field | ||
- cc: 'array' - Comma separated list or an array of recipients email addresses (`string`) that will appear on the Cc: field | ||
- bcc: 'array' - Comma separated list or an array of recipients email addresses (`string`) that will appear on the Bcc: field | ||
- replyTo : 'string' - An email address that will appear on the Reply-To: field | ||
- subject: 'string' - The subject of the email with context injected. | ||
- html: 'string' - The HTML version of the message as an Unicode string, with context injected. | ||
- text : 'string' - The plaintext version of the message as an Unicode string, with context injected | ||
|
||
- opts: 'object' - Object containing options: | ||
- templatePath: 'string' - the relative path to the message's templates. | ||
- context: 'object' - Object containing context for the message (such as - variables that will be used in copy) | ||
|
||
- Returns: 'object' with following properties: | ||
- accepted : 'array' of email addresses accepted - eg. [ '[email protected]' ] | ||
- rejected : 'array' of email addresses rejected - eg. [], | ||
- envelopeTime | ||
- messageTime | ||
- messageSize | ||
- response | ||
- envelope | ||
- messageId | ||
- sendMail: 'function' - Calls `createMessage` to generate an message and uses [fastify-nodemailer](https://github.com/lependu/fastify-nodemailer) to send the generated email. | ||
- Accepts the following arguments: | ||
- message: 'object' | ||
*This is a valid 'message' object as per the Nodemailer API* | ||
- from: 'string' - The email address the email is to be sent from. | ||
- to: 'array' - Comma separated list or an array of recipients email addresses (`string`) that will appear on the To: field | ||
- cc: 'array' - Comma separated list or an array of recipients email addresses (`string`) that will appear on the Cc: field | ||
- bcc: 'array' - Comma separated list or an array of recipients email addresses (`string`) that will appear on the Bcc: field | ||
- replyTo : 'string' - An email address that will appear on the Reply-To: field | ||
- subject: 'string' - The subject of the email with context injected. | ||
- html: 'string' - The HTML version of the message as an Unicode string, with context injected. | ||
- text : 'string' - The plaintext version of the message as an Unicode string, with context injected | ||
|
||
- opts: 'object' - Object containing options: | ||
- templatePath: 'string' - the relative path to the message's templates. | ||
- context: 'object' - Object containing context for the message (such as - variables that will be used in copy) | ||
|
||
- Returns: 'object' with following properties: | ||
- accepted : 'array' of email addresses accepted - eg. [ '[email protected]' ] | ||
- rejected : 'array' of email addresses rejected - eg. [], | ||
- envelopeTime | ||
- messageTime | ||
- messageSize | ||
- response | ||
- envelope | ||
- messageId | ||
|
||
- createMessage: 'function' - Generates a message object where the data provided is updated to use templates where available with context variables injected | ||
- Accepts the following arguments: | ||
- Accepts the following arguments: | ||
- message: 'object' | ||
- fields as above | ||
- templatePath: 'string' - the relative path to the message's templates. | ||
- context: 'object' - Object containing context for the message (such as - variables that will be used in copy) | ||
|
||
For more details on this response see the Nodemail documentation [View nodemailer's docs here](https://nodemailer.com/smtp/) | ||
For more details on this response see the nodemailer documentation [View nodemailer's docs here](https://nodemailer.com/smtp/) | ||
|
||
### Testing | ||
|
||
[Tap](https://node-tap.org/) is used for testing. To run tests: | ||
|
||
```sh | ||
npm test | ||
``` | ||
$ npm test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ module.exports = async function (fastify, options) { | |
'</html>\n' | ||
|
||
const message = { | ||
to: ['[email protected]'], | ||
to: '[email protected]', | ||
from: '[email protected]', | ||
subject: 'Test Subject', | ||
html: testHtml, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export MAILGUN_API_KEY=1234 | ||
export MAILGUN_DOMAIN=sandbox...mailgun.org | ||
export RECIPIENTS[email protected] | ||
export [email protected] | ||
export RECIPIENT[email protected] | ||
export [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] could we remove?