Skip to content

Commit c523594

Browse files
feat: first commit v0.1.0
1 parent f73f95a commit c523594

File tree

13 files changed

+579
-2
lines changed

13 files changed

+579
-2
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Set default behavior to automatically convert line endings
2+
* text=auto eol=lf

.github/.stale.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Number of days of inactivity before an issue becomes stale
2+
daysUntilStale: 15
3+
# Number of days of inactivity before a stale issue is closed
4+
daysUntilClose: 7
5+
# Issues with these labels will never be considered stale
6+
exemptLabels:
7+
- "discussion"
8+
- "feature request"
9+
- "bug"
10+
- "help wanted"
11+
- "plugin suggestion"
12+
- "good first issue"
13+
# Label to use when marking an issue as stale
14+
staleLabel: stale
15+
# Comment to post when marking an issue as stale. Set to `false` to disable
16+
markComment: >
17+
This issue has been automatically marked as stale because it has not had
18+
recent activity. It will be closed if no further activity occurs. Thank you
19+
for your contributions.
20+
# Comment to post when closing a stale issue. Set to `false` to disable
21+
closeComment: false

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
7+
open-pull-requests-limit: 10
8+
9+
- package-ecosystem: "npm"
10+
directory: "/"
11+
schedule:
12+
interval: "weekly"
13+
open-pull-requests-limit: 10

.github/tests_checker.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
comment: |
2+
Hello! Thank you for contributing!
3+
It appears that you have changed the code, but the tests that verify your change are missing. Could you please add them?
4+
fileExtensions:
5+
- '.js'
6+
7+
testDir: 'test'

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
- next
9+
- 'v*'
10+
paths-ignore:
11+
- 'docs/**'
12+
- '*.md'
13+
pull_request:
14+
paths-ignore:
15+
- 'docs/**'
16+
- '*.md'
17+
18+
jobs:
19+
test:
20+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
21+
with:
22+
license-check: true
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: package-manager-ci
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
- next
9+
- 'v*'
10+
paths-ignore:
11+
- 'docs/**'
12+
- '*.md'
13+
pull_request:
14+
paths-ignore:
15+
- 'docs/**'
16+
- '*.md'
17+
18+
jobs:
19+
test:
20+
uses: fastify/workflows/.github/workflows/plugins-ci-package-manager.yml@v3

.gitignore

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Clinic
14+
.clinic
15+
16+
# Runtime data
17+
pids
18+
*.pid
19+
*.seed
20+
*.pid.lock
21+
22+
# Directory for instrumented libs generated by jscoverage/JSCover
23+
lib-cov
24+
25+
# Coverage directory used by tools like istanbul
26+
coverage
27+
*.lcov
28+
29+
# nyc test coverage
30+
.nyc_output
31+
32+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
33+
.grunt
34+
35+
# Bower dependency directory (https://bower.io/)
36+
bower_components
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (https://nodejs.org/api/addons.html)
42+
build/Release
43+
44+
# Dependency directories
45+
node_modules/
46+
jspm_packages/
47+
48+
# Snowpack dependency directory (https://snowpack.dev/)
49+
web_modules/
50+
51+
# TypeScript cache
52+
*.tsbuildinfo
53+
54+
# Optional npm cache directory
55+
.npm
56+
57+
# Optional eslint cache
58+
.eslintcache
59+
60+
# Optional stylelint cache
61+
.stylelintcache
62+
63+
# Microbundle cache
64+
.rpt2_cache/
65+
.rts2_cache_cjs/
66+
.rts2_cache_es/
67+
.rts2_cache_umd/
68+
69+
# Optional REPL history
70+
.node_repl_history
71+
72+
# Output of 'npm pack'
73+
*.tgz
74+
75+
# Yarn Integrity file
76+
.yarn-integrity
77+
78+
# dotenv environment variable files
79+
.env
80+
.env.development.local
81+
.env.test.local
82+
.env.production.local
83+
.env.local
84+
85+
# parcel-bundler cache (https://parceljs.org/)
86+
.cache
87+
.parcel-cache
88+
89+
# Next.js build output
90+
.next
91+
out
92+
93+
# Nuxt.js build / generate output
94+
.nuxt
95+
dist
96+
97+
# Gatsby files
98+
.cache/
99+
# Comment in the public line in if your project uses Gatsby and not Next.js
100+
# https://nextjs.org/blog/next-9-1#public-directory-support
101+
# public
102+
103+
# vuepress build output
104+
.vuepress/dist
105+
106+
# vuepress v2.x temp and cache directory
107+
.temp
108+
.cache
109+
110+
# Docusaurus cache and generated files
111+
.docusaurus
112+
113+
# Serverless directories
114+
.serverless/
115+
116+
# FuseBox cache
117+
.fusebox/
118+
119+
# DynamoDB Local files
120+
.dynamodb/
121+
122+
# TernJS port file
123+
.tern-port
124+
125+
# Stores VSCode versions used for testing VSCode extensions
126+
.vscode-test
127+
128+
# yarn v2
129+
.yarn/cache
130+
.yarn/unplugged
131+
.yarn/build-state.yml
132+
.yarn/install-state.gz
133+
.pnp.*
134+
135+
# Vim swap files
136+
*.swp
137+
138+
# macOS files
139+
.DS_Store
140+
141+
# lock files
142+
package-lock.json
143+
pnpm-lock.yaml
144+
yarn.lock
145+
bun.lockb
146+
147+
# editor files
148+
.vscode
149+
.idea
150+
151+
# tap files
152+
.tap/

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

README.md

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,120 @@
1-
# fastify-mailer
2-
Fastify nodemailer connection plugin
1+
# fastify-mailer-provider
2+
3+
This module provides a way to send email using `nodemailer`.
4+
5+
## Install
6+
```
7+
npm i fastify-mailer-provider
8+
```
9+
10+
## Usage
11+
Add it to you project with `register` and you are done!
12+
13+
```js
14+
const fastify = require('fastify')()
15+
16+
fastify.register(require('fastify-mailer-provider'), {
17+
pool: true,
18+
host: 'smtp.example.com',
19+
port: 465,
20+
secure: true, // use TLS
21+
auth: {
22+
user: 'username',
23+
pass: 'password'
24+
}
25+
})
26+
27+
28+
fastify.get('/sendmail/:email', async (req, reply) => {
29+
const {email} = req.params
30+
31+
await fastify.mailer.sendMail({
32+
from: 'sender@example.com',
33+
to: email,
34+
subject: 'foo',
35+
text: 'bar'
36+
})
37+
return reply.status(204).send()
38+
})
39+
40+
fastify.listen({ port: 3000 }, err => {
41+
if (err) throw err
42+
})
43+
```
44+
45+
You can also set an email provider for identification:
46+
```js
47+
const fastify = require('fastify')()
48+
49+
fastify.register(require('fastify-mailer-provider'), {
50+
provider: 'aws', // using aws to send email
51+
pool: true,
52+
host: 'smtp.example.com',
53+
port: 465,
54+
secure: true,
55+
auth: {
56+
user: 'username',
57+
pass: 'password'
58+
}
59+
})
60+
61+
62+
fastify.get('/sendmail/:email', async (req, reply) => {
63+
const {email} = req.params
64+
65+
await fastify.mailer.aws.sendMail({
66+
from: 'sender@example.com',
67+
to: email,
68+
subject: 'foo',
69+
text: 'bar'
70+
})
71+
return reply.send({
72+
provider: fastify.mailer.aws.provider // { provider: 'aws' }
73+
})
74+
})
75+
76+
fastify.listen({ port: 3000 }, err => {
77+
if (err) throw err
78+
})
79+
```
80+
81+
You can also set multiply an email providers:
82+
```js
83+
const fastify = require('fastify')()
84+
85+
fastify.register(require('fastify-mailer-provider'), {
86+
provider: 'aws',
87+
// ...
88+
})
89+
90+
fastify.register(require('fastify-mailer-provider'), {
91+
provider: 'google',
92+
// ...
93+
})
94+
95+
fastify.register(require('fastify-mailer-provider'), {
96+
provider: 'sendgrid',
97+
// ...
98+
})
99+
100+
fastify.get('/sendmail/:email', async (req, reply) => {
101+
const {email} = req.params
102+
103+
await fastify.mailer.aws.sendMail({ /*...*/ })
104+
await fastify.mailer.google.sendMail({ /*...*/ })
105+
await fastify.mailer.sendgrid.sendMail({ /*...*/ })
106+
// ...
107+
})
108+
109+
fastify.listen({ port: 3000 }, err => {
110+
if (err) throw err
111+
})
112+
```
113+
114+
## Documentation
115+
116+
More details about nodemailer documentation, see [nodemailer docs](https://nodemailer.com/about/).
117+
118+
## License
119+
120+
[MIT License](https://github.com/leandroandrade/fastify-mailer-provider/blob/main/LICENSE/)

example.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const fastify = require('fastify')()
2+
3+
fastify.register(require('./'), {
4+
provider: 'sendgrid',
5+
pool: true,
6+
host: 'smtp.example.com',
7+
port: 465,
8+
secure: true,
9+
auth: {
10+
user: 'user',
11+
pass: 'pass'
12+
}
13+
})
14+
15+
fastify.get('/sendmail/:email', async (req, reply) => {
16+
const { email } = req.params
17+
18+
await fastify.mailer.sendgrid.sendMail({
19+
from: 'sender@example.com',
20+
to: email,
21+
subject: 'foo',
22+
text: 'bar'
23+
})
24+
return reply.status(204).send()
25+
})
26+
27+
fastify.listen({ port: 3000 }, err => {
28+
if (err) throw err
29+
})

0 commit comments

Comments
 (0)