diff --git a/backend/src/email/email.service.ts b/backend/src/email/email.service.ts index cfbeab26..838f5bea 100644 --- a/backend/src/email/email.service.ts +++ b/backend/src/email/email.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from "@nestjs/common"; +import { Injectable, InternalServerErrorException } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; import { User } from "@prisma/client"; import * as nodemailer from "nodemailer"; @@ -19,6 +19,9 @@ export class EmailService { }); async sendMail(recipientEmail: string, shareId: string, creator: User) { + if (this.config.get("EMAIL_RECIPIENTS_ENABLED") == "false") + throw new InternalServerErrorException("Email service disabled"); + const shareUrl = `${this.config.get("APP_URL")}/share/${shareId}`; const creatorIdentifier = creator.firstName && creator.lastName diff --git a/frontend/.env.example b/frontend/.env.example index 65ef8ee5..80502371 100644 --- a/frontend/.env.example +++ b/frontend/.env.example @@ -1,4 +1,5 @@ SHOW_HOME_PAGE=true ALLOW_REGISTRATION=true MAX_FILE_SIZE=1000000000 -ALLOW_UNAUTHENTICATED_SHARES=false \ No newline at end of file +ALLOW_UNAUTHENTICATED_SHARES=false +EMAIL_RECIPIENTS_ENABLED=false \ No newline at end of file diff --git a/frontend/next.config.js b/frontend/next.config.js index 99405314..d0c3fc59 100644 --- a/frontend/next.config.js +++ b/frontend/next.config.js @@ -5,7 +5,8 @@ const nextConfig = { ALLOW_REGISTRATION: process.env.ALLOW_REGISTRATION, SHOW_HOME_PAGE: process.env.SHOW_HOME_PAGE, MAX_FILE_SIZE: process.env.MAX_FILE_SIZE, - ALLOW_UNAUTHENTICATED_SHARES: process.env.ALLOW_UNAUTHENTICATED_SHARES + ALLOW_UNAUTHENTICATED_SHARES: process.env.ALLOW_UNAUTHENTICATED_SHARES, + EMAIL_RECIPIENTS_ENABLED: process.env.EMAIL_RECIPIENTS_ENABLED } } diff --git a/frontend/src/components/upload/modals/showCreateUploadModal.tsx b/frontend/src/components/upload/modals/showCreateUploadModal.tsx index cca61710..d660b4a5 100644 --- a/frontend/src/components/upload/modals/showCreateUploadModal.tsx +++ b/frontend/src/components/upload/modals/showCreateUploadModal.tsx @@ -225,31 +225,36 @@ const CreateUploadModalBody = ({ {ExpirationPreview({ form })} - - Email recipients - - `+ ${query}`} - onCreate={(query) => { - if (!query.match(/^\S+@\S+\.\S+$/)) { - form.setFieldError("recipients", "Invalid email address"); - } else { - form.setFieldError("recipients", null); - form.setFieldValue("recipients", [ - ...form.values.recipients, - query, - ]); - return query; - } - }} - /> - - + {publicRuntimeConfig.EMAIL_RECIPIENTS_ENABLED == "true" && ( + + Email recipients + + `+ ${query}`} + onCreate={(query) => { + if (!query.match(/^\S+@\S+\.\S+$/)) { + form.setFieldError( + "recipients", + "Invalid email address" + ); + } else { + form.setFieldError("recipients", null); + form.setFieldValue("recipients", [ + ...form.values.recipients, + query, + ]); + return query; + } + }} + /> + + + )} Security options