diff --git a/.env.example b/.env.example index a8efb79..3685082 100644 --- a/.env.example +++ b/.env.example @@ -24,7 +24,8 @@ REFRESH_TOKEN_TTL_DAYS=14 SMTP_HOST= SMTP_PORT=587 SMTP_USER= -SMTP_PASS= +SMTP_PASS= # Traditional password auth +SMTP_TOKEN= # OAuth2/App token auth (takes precedence over SMTP_PASS) SMTP_FROM= SMTP_SECURE=false diff --git a/backend/src/routes/planner.ts b/backend/src/routes/planner.ts index 58e1ba0..0852913 100644 --- a/backend/src/routes/planner.ts +++ b/backend/src/routes/planner.ts @@ -44,7 +44,7 @@ export async function plannerRoutes(app: FastifyInstance) { const smtpHost = process.env.SMTP_HOST; const smtpUser = process.env.SMTP_USER; - const smtpPass = process.env.SMTP_PASS; + const smtpPass = process.env.SMTP_TOKEN || process.env.SMTP_PASS; // Token takes precedence const smtpPort = parseInt(process.env.SMTP_PORT ?? "587"); const smtpSecure = process.env.SMTP_SECURE === "true"; const smtpFrom = process.env.SMTP_FROM ?? smtpUser; @@ -190,7 +190,7 @@ Sent from MedAssist-ng Medication Planner`; if (notificationSettings.emailEnabled && email) { const smtpHost = process.env.SMTP_HOST; const smtpUser = process.env.SMTP_USER; - const smtpPass = process.env.SMTP_PASS; + const smtpPass = process.env.SMTP_TOKEN || process.env.SMTP_PASS; // Token takes precedence const smtpPort = parseInt(process.env.SMTP_PORT ?? "587"); const smtpSecure = process.env.SMTP_SECURE === "true"; const smtpFrom = process.env.SMTP_FROM ?? smtpUser; diff --git a/backend/src/routes/settings.ts b/backend/src/routes/settings.ts index 5458a43..4d99a5b 100644 --- a/backend/src/routes/settings.ts +++ b/backend/src/routes/settings.ts @@ -136,7 +136,7 @@ export async function settingsRoutes(app: FastifyInstance) { smtpUser: process.env.SMTP_USER ?? "", smtpFrom: process.env.SMTP_FROM ?? "", smtpSecure: process.env.SMTP_SECURE === "true", - hasSmtpPassword: !!process.env.SMTP_PASS, + hasSmtpPassword: !!(process.env.SMTP_TOKEN || process.env.SMTP_PASS), // Reminder state lastAutoEmailSent: reminderState.lastAutoEmailSent, nextScheduledCheck: reminderState.nextScheduledCheck, @@ -188,7 +188,7 @@ export async function settingsRoutes(app: FastifyInstance) { const smtpHost = process.env.SMTP_HOST; const smtpUser = process.env.SMTP_USER; - const smtpPass = process.env.SMTP_PASS; + const smtpPass = process.env.SMTP_TOKEN || process.env.SMTP_PASS; // Token takes precedence const smtpPort = parseInt(process.env.SMTP_PORT ?? "587"); const smtpSecure = process.env.SMTP_SECURE === "true"; const smtpFrom = process.env.SMTP_FROM ?? smtpUser; diff --git a/backend/src/services/intake-reminder-scheduler.ts b/backend/src/services/intake-reminder-scheduler.ts index db80463..88a8482 100644 --- a/backend/src/services/intake-reminder-scheduler.ts +++ b/backend/src/services/intake-reminder-scheduler.ts @@ -130,7 +130,7 @@ function getUpcomingIntakes(medName: string, slices: Slice[], minutesBefore: num async function sendIntakeReminderEmail(email: string, intakes: UpcomingIntake[], language: Language): Promise<{ success: boolean; error?: string }> { const smtpHost = process.env.SMTP_HOST; const smtpUser = process.env.SMTP_USER; - const smtpPass = process.env.SMTP_PASS; + const smtpPass = process.env.SMTP_TOKEN || process.env.SMTP_PASS; // Token takes precedence const smtpPort = parseInt(process.env.SMTP_PORT ?? "587"); const smtpSecure = process.env.SMTP_SECURE === "true"; const smtpFrom = process.env.SMTP_FROM ?? smtpUser; diff --git a/backend/src/services/reminder-scheduler.ts b/backend/src/services/reminder-scheduler.ts index d00945a..1969bb8 100644 --- a/backend/src/services/reminder-scheduler.ts +++ b/backend/src/services/reminder-scheduler.ts @@ -258,7 +258,7 @@ async function getMedicationsNeedingReminder(reminderDaysBefore: number, languag async function sendReminderEmail(email: string, lowStock: LowStockItem[], language: Language, isRepeatDaily: boolean = false): Promise<{ success: boolean; error?: string }> { const smtpHost = process.env.SMTP_HOST; const smtpUser = process.env.SMTP_USER; - const smtpPass = process.env.SMTP_PASS; + const smtpPass = process.env.SMTP_TOKEN || process.env.SMTP_PASS; // Token takes precedence const smtpPort = parseInt(process.env.SMTP_PORT ?? "587"); const smtpSecure = process.env.SMTP_SECURE === "true"; const smtpFrom = process.env.SMTP_FROM ?? smtpUser;