From 2d028d18e5e76c38f8ae64969bc0eaacc14fdbd5 Mon Sep 17 00:00:00 2001 From: IllimarR Date: Thu, 13 Mar 2025 14:50:15 +0200 Subject: [PATCH] feat: possibility to set mail from name (#4864) Co-authored-by: Piyush Gupta Co-authored-by: Johannes --- .env.example | 2 ++ apps/web/modules/email/index.tsx | 3 ++- docker/docker-compose.yml | 1 + docker/formbricks.sh | 5 +++++ docs/self-hosting/advanced/migration.mdx | 1 + docs/self-hosting/configuration/environment-variables.mdx | 1 + docs/self-hosting/configuration/smtp.mdx | 5 +++++ packages/lib/constants.ts | 1 + packages/lib/env.ts | 2 ++ turbo.json | 1 + 10 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index ce10efce27..6243260549 100644 --- a/.env.example +++ b/.env.example @@ -39,6 +39,7 @@ DATABASE_URL='postgresql://postgres:postgres@localhost:5432/formbricks?schema=pu # See optional configurations below if you want to disable these features. MAIL_FROM=noreply@example.com +MAIL_FROM_NAME=Formbricks SMTP_HOST=localhost SMTP_PORT=1025 # Enable SMTP_SECURE_ENABLED for TLS (port 465) @@ -207,3 +208,4 @@ UNKEY_ROOT_KEY= # Enable Prometheus metrics # PROMETHEUS_ENABLED= # PROMETHEUS_EXPORTER_PORT= + diff --git a/apps/web/modules/email/index.tsx b/apps/web/modules/email/index.tsx index d7c1720ecf..b99074d768 100644 --- a/apps/web/modules/email/index.tsx +++ b/apps/web/modules/email/index.tsx @@ -6,6 +6,7 @@ import type SMTPTransport from "nodemailer/lib/smtp-transport"; import { DEBUG, MAIL_FROM, + MAIL_FROM_NAME, SMTP_AUTHENTICATED, SMTP_HOST, SMTP_PASSWORD, @@ -69,7 +70,7 @@ export const sendEmail = async (emailData: SendEmailDataProps): Promise } as SMTPTransport.Options); const emailDefaults = { - from: `Formbricks <${MAIL_FROM ?? "noreply@formbricks.com"}>`, + from: `${MAIL_FROM_NAME ?? "Formbricks"} <${MAIL_FROM ?? "noreply@formbricks.com"}>`, }; await transporter.sendMail({ ...emailDefaults, ...emailData }); diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 97fa7baf1e..4e87afb250 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -36,6 +36,7 @@ x-environment: &environment # Email Configuration # MAIL_FROM: + # MAIL_FROM_NAME: # SMTP_HOST: # SMTP_PORT: # SMTP_USER: diff --git a/docker/formbricks.sh b/docker/formbricks.sh index d941c6b5af..95e039e6c3 100755 --- a/docker/formbricks.sh +++ b/docker/formbricks.sh @@ -224,6 +224,9 @@ EOT echo -n "Enter your SMTP configured Email ID: " read mail_from + echo -n "Enter your SMTP configured Email Name: " + read mail_from_name + echo -n "Enter your SMTP Host URL: " read smtp_host @@ -244,6 +247,7 @@ EOT else mail_from="" + mail_from_name="" smtp_host="" smtp_port="" smtp_user="" @@ -270,6 +274,7 @@ EOT if [[ -n $mail_from ]]; then sed -i "s|# MAIL_FROM:|MAIL_FROM: \"$mail_from\"|" docker-compose.yml + sed -i "s|# MAIL_FROM_NAME:|MAIL_FROM_NAME: \"$mail_from_name\"|" docker-compose.yml sed -i "s|# SMTP_HOST:|SMTP_HOST: \"$smtp_host\"|" docker-compose.yml sed -i "s|# SMTP_PORT:|SMTP_PORT: \"$smtp_port\"|" docker-compose.yml sed -i "s|# SMTP_SECURE_ENABLED:|SMTP_SECURE_ENABLED: $smtp_secure_enabled|" docker-compose.yml diff --git a/docs/self-hosting/advanced/migration.mdx b/docs/self-hosting/advanced/migration.mdx index e2a889169a..858c95a1cb 100644 --- a/docs/self-hosting/advanced/migration.mdx +++ b/docs/self-hosting/advanced/migration.mdx @@ -1039,6 +1039,7 @@ x-environment: &environment # Email Configuration MAIL_FROM: + MAIL_FROM_NAME: SMTP_HOST: SMTP_PORT: SMTP_SECURE_ENABLED: diff --git a/docs/self-hosting/configuration/environment-variables.mdx b/docs/self-hosting/configuration/environment-variables.mdx index 7281ebf19b..77f768ce22 100644 --- a/docs/self-hosting/configuration/environment-variables.mdx +++ b/docs/self-hosting/configuration/environment-variables.mdx @@ -33,6 +33,7 @@ These variables are present inside your machine’s docker-compose file. Restart | RATE_LIMITING_DISABLED | Disables rate limiting if set to 1. | optional | | | INVITE_DISABLED | Disables the ability for invited users to create an account if set to 1. | optional | | | MAIL_FROM | Email address to send emails from. | optional (required if email services are to be enabled) | | +| MAIL_FROM_NAME | Email name/title to send emails from. | optional (required if email services are to be enabled) | | | SMTP_HOST | Host URL of your SMTP server. | optional (required if email services are to be enabled) | | | SMTP_PORT | Host Port of your SMTP server. | optional (required if email services are to be enabled) | | | SMTP_USER | Username for your SMTP Server. | optional (required if email services are to be enabled) | | diff --git a/docs/self-hosting/configuration/smtp.mdx b/docs/self-hosting/configuration/smtp.mdx index d739becec7..0c19fcf8a5 100644 --- a/docs/self-hosting/configuration/smtp.mdx +++ b/docs/self-hosting/configuration/smtp.mdx @@ -33,6 +33,7 @@ To enable email functionality, configure the following environment variables: ```bash # Basic SMTP Configuration MAIL_FROM=noreply@yourdomain.com +MAIL_FROM_NAME=Formbricks SMTP_HOST=smtp.yourprovider.com SMTP_PORT=587 SMTP_USER=your_username @@ -75,6 +76,7 @@ If you're using the one-click setup with Docker Compose, you can either: environment: # Email Configuration MAIL_FROM: noreply@yourdomain.com + MAIL_FROM_NAME: Formbricks SMTP_HOST: smtp.yourprovider.com SMTP_PORT: 587 SMTP_USER: your_username @@ -95,6 +97,7 @@ environment: ```bash MAIL_FROM=noreply@yourdomain.com +MAIL_FROM_NAME=Formbricks SMTP_HOST=smtp.sendgrid.net SMTP_PORT=587 SMTP_USER=apikey @@ -105,6 +108,7 @@ SMTP_PASSWORD=your_sendgrid_api_key ```bash MAIL_FROM=noreply@yourdomain.com +MAIL_FROM_NAME=Formbricks SMTP_HOST=email-smtp.us-east-1.amazonaws.com SMTP_PORT=587 SMTP_USER=your_ses_access_key @@ -115,6 +119,7 @@ SMTP_PASSWORD=your_ses_secret_key ```bash MAIL_FROM=your_email@gmail.com +MAIL_FROM_NAME=Formbricks SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=your_email@gmail.com diff --git a/packages/lib/constants.ts b/packages/lib/constants.ts index c936224efa..095ba2fe35 100644 --- a/packages/lib/constants.ts +++ b/packages/lib/constants.ts @@ -83,6 +83,7 @@ export const SMTP_PASSWORD = env.SMTP_PASSWORD; export const SMTP_AUTHENTICATED = env.SMTP_AUTHENTICATED !== "0"; export const SMTP_REJECT_UNAUTHORIZED_TLS = env.SMTP_REJECT_UNAUTHORIZED_TLS !== "0"; export const MAIL_FROM = env.MAIL_FROM; +export const MAIL_FROM_NAME = env.MAIL_FROM_NAME; export const NEXTAUTH_SECRET = env.NEXTAUTH_SECRET; export const ITEMS_PER_PAGE = 30; diff --git a/packages/lib/env.ts b/packages/lib/env.ts index 95267506dd..c2b13e147f 100644 --- a/packages/lib/env.ts +++ b/packages/lib/env.ts @@ -49,6 +49,7 @@ export const env = createEnv({ INTERCOM_SECRET_KEY: z.string().optional(), IS_FORMBRICKS_CLOUD: z.enum(["1", "0"]).optional(), MAIL_FROM: z.string().email().optional(), + MAIL_FROM_NAME: z.string().optional(), NEXTAUTH_SECRET: z.string().min(1), NOTION_OAUTH_CLIENT_ID: z.string().optional(), NOTION_OAUTH_CLIENT_SECRET: z.string().optional(), @@ -173,6 +174,7 @@ export const env = createEnv({ INTERCOM_SECRET_KEY: process.env.INTERCOM_SECRET_KEY, IS_FORMBRICKS_CLOUD: process.env.IS_FORMBRICKS_CLOUD, MAIL_FROM: process.env.MAIL_FROM, + MAIL_FROM_NAME: process.env.MAIL_FROM_NAME, NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET, NEXT_PUBLIC_FORMBRICKS_API_HOST: process.env.NEXT_PUBLIC_FORMBRICKS_API_HOST, NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID: process.env.NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID, diff --git a/turbo.json b/turbo.json index 8235a1c082..c8ac3cc8fe 100644 --- a/turbo.json +++ b/turbo.json @@ -119,6 +119,7 @@ "IS_FORMBRICKS_CLOUD", "INTERCOM_SECRET_KEY", "MAIL_FROM", + "MAIL_FROM_NAME", "NEXT_PUBLIC_LAYER_API_KEY", "NEXT_PUBLIC_DOCSEARCH_APP_ID", "NEXT_PUBLIC_DOCSEARCH_API_KEY",