Skip to content

Commit

Permalink
Make SMTP config optional
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Nov 10, 2022
1 parent 7bab35e commit 4d77f2b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
22 changes: 12 additions & 10 deletions plugins/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import nodemailer from 'nodemailer'
* @see https://github.com/nodemailer/nodemailer
*/
export default fp(async function (fastify, opts) {
const transport = nodemailer.createTransport({
host: fastify.config.SMTP_HOST,
port: fastify.config.SMTP_PORT,
secure: fastify.config.SMTP_SECURE,
auth: {
user: fastify.config.SMTP_USER,
pass: fastify.config.SMTP_PASS
}
})
if (fastify.config.SMTP_HOST && fastify.config.SMTP_PORT && fastify.config.SMTP_SECURE && fastify.config.SMTP_USER && fastify.config.SMTP_PASS) {
const transport = nodemailer.createTransport({
host: fastify.config.SMTP_HOST,
port: fastify.config.SMTP_PORT,
secure: fastify.config.SMTP_SECURE,
auth: {
user: fastify.config.SMTP_USER,
pass: fastify.config.SMTP_PASS
}
})

fastify.decorate('email', transport)
fastify.decorate('email', transport)
}
}, {
name: 'email',
dependencies: ['env']
Expand Down
5 changes: 1 addition & 4 deletions plugins/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ export const schema = {
type: 'object',
required: [
'JWT_SECRET',
'COOKIE_SECRET',
'SMTP_HOST',
'SMTP_USER',
'SMTP_PASS'
'COOKIE_SECRET'
],
properties: {
ENV: {
Expand Down

0 comments on commit 4d77f2b

Please sign in to comment.