diff --git a/.env.example b/.env.example index a97e03d..39627b7 100644 --- a/.env.example +++ b/.env.example @@ -25,7 +25,7 @@ DB_PORT=5432 # === Email (Opcional) === # Provider: Resend (https://resend.com) RESEND_API_KEY= -RESEND_FROM_EMAIL=OpenMonetis +RESEND_FROM_EMAIL="OpenMonetis " # === OAuth (Opcional) === # Google: https://console.cloud.google.com/apis/credentials diff --git a/CHANGELOG.md b/CHANGELOG.md index b450c0d..4c89aa4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ Todas as mudanças notáveis deste projeto serão documentadas neste arquivo. O formato é baseado em [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/), e este projeto adere ao [Versionamento Semântico](https://semver.org/lang/pt-BR/). +## [1.6.3] - 2026-02-19 + +### Corrigido + +- E-mail Resend: variável `RESEND_FROM_EMAIL` não era lida do `.env` (valores com espaço precisam estar entre aspas). Leitura centralizada em `lib/email/resend.ts` com `getResendFromEmail()` e carregamento explícito do `.env` no contexto de Server Actions + +### Alterado + +- `.env.example`: `RESEND_FROM_EMAIL` com valor entre aspas e comentário para uso em Docker/produção +- `docker-compose.yml`: env do app passa `RESEND_FROM_EMAIL` (em vez de `EMAIL_FROM`) para o container, alinhado ao nome usado pela aplicação + ## [1.6.2] - 2026-02-19 ### Corrigido diff --git a/app/(dashboard)/pagadores/[pagadorId]/actions.ts b/app/(dashboard)/pagadores/[pagadorId]/actions.ts index c30e862..e3871ab 100644 --- a/app/(dashboard)/pagadores/[pagadorId]/actions.ts +++ b/app/(dashboard)/pagadores/[pagadorId]/actions.ts @@ -5,6 +5,7 @@ import { revalidatePath } from "next/cache"; import { Resend } from "resend"; import { z } from "zod"; import { lancamentos, pagadores } from "@/db/schema"; +import { getResendFromEmail } from "@/lib/email/resend"; import { getUser } from "@/lib/auth/server"; import { db } from "@/lib/db"; import { @@ -418,8 +419,7 @@ export async function sendPagadorSummaryAction( } const resendApiKey = process.env.RESEND_API_KEY; - const resendFrom = - process.env.RESEND_FROM_EMAIL ?? "OpenMonetis "; + const resendFrom = getResendFromEmail(); if (!resendApiKey) { return { diff --git a/docker-compose.yml b/docker-compose.yml index a8c432f..26b6b8e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -93,7 +93,7 @@ services: # Configurações de email (se usar) RESEND_API_KEY: ${RESEND_API_KEY:-} - EMAIL_FROM: ${EMAIL_FROM:-} + RESEND_FROM_EMAIL: ${RESEND_FROM_EMAIL:-} # Configurações de OAuth (se usar) GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID:-} diff --git a/lib/email/resend.ts b/lib/email/resend.ts new file mode 100644 index 0000000..99482bd --- /dev/null +++ b/lib/email/resend.ts @@ -0,0 +1,16 @@ +import { config } from "dotenv"; + +/** + * Endereço "from" para envio de e-mails via Resend. + * Lê RESEND_FROM_EMAIL do .env (valor deve estar entre aspas se tiver espaço: + * Garante carregamento do .env no contexto da chamada (ex.: Server Actions). + */ +const FALLBACK_FROM = "OpenMonetis "; + +export function getResendFromEmail(): string { + // Garantir que .env foi carregado (não sobrescreve variáveis já definidas) + config({ path: ".env" }); + const raw = process.env.RESEND_FROM_EMAIL; + const value = typeof raw === "string" ? raw.trim() : ""; + return value.length > 0 ? value : FALLBACK_FROM; +} diff --git a/lib/pagadores/notifications.ts b/lib/pagadores/notifications.ts index 1c8fb19..92e92d5 100644 --- a/lib/pagadores/notifications.ts +++ b/lib/pagadores/notifications.ts @@ -1,6 +1,7 @@ import { inArray } from "drizzle-orm"; import { Resend } from "resend"; import { pagadores } from "@/db/schema"; +import { getResendFromEmail } from "@/lib/email/resend"; import { db } from "@/lib/db"; type ActionType = "created" | "deleted"; @@ -118,8 +119,7 @@ export async function sendPagadorAutoEmails({ } const resendApiKey = process.env.RESEND_API_KEY; - const resendFrom = - process.env.RESEND_FROM_EMAIL ?? "OpenMonetis "; + const resendFrom = getResendFromEmail(); if (!resendApiKey) { console.warn( diff --git a/package.json b/package.json index 6797940..df75ced 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openmonetis", - "version": "1.6.2", + "version": "1.6.3", "private": true, "scripts": { "dev": "next dev --turbopack",