Skip to content

feat: support separate SMTP credentials (username + password) for outgoing server#255

Open
SaschaOnTour wants to merge 8 commits intoavihaymenahem:mainfrom
SaschaOnTour:main
Open

feat: support separate SMTP credentials (username + password) for outgoing server#255
SaschaOnTour wants to merge 8 commits intoavihaymenahem:mainfrom
SaschaOnTour:main

Conversation

@SaschaOnTour
Copy link
Copy Markdown

@SaschaOnTour SaschaOnTour commented Apr 14, 2026

Summary

Allow users to configure completely separate credentials (username + password) for outgoing SMTP, independent from incoming IMAP credentials. This also fixes a bug where the SMTP password field was present in the UI but the value was silently discarded on save.

Changes

  • Bug fix: AddImapAccount.tsx line 387 had password: form.samePassword ? form.password : form.password — both branches returned the IMAP password, so the SMTP password was never persisted
  • DB migration v24: Add smtp_username and smtp_password columns to accounts table
  • accounts.ts: Extended DbAccount interface, insertImapAccount, and decryptAccountTokens for the new fields
  • imapConfigBuilder.ts: buildSmtpConfig now uses smtp_username / smtp_password with 3-level fallback to IMAP values for backward compatibility
  • AddImapAccount.tsx: Renamed checkbox to "Use same credentials as IMAP", added SMTP Username field, fixed save to pass separate credentials
  • Refactor: Replaced 6 identical try/catch blocks in decryptAccountTokens with an ENCRYPTED_FIELDS loop
  • Tests: Added 51 tests for AddImapAccount.tsx (previously 0 coverage), 5 for imapConfigBuilder, 5 for accounts DB layer

Type of Change

Testing

  • Existing tests pass (npm run test) — 1619 tests, 134 files
  • New tests added (if applicable) — 61 new tests across 3 files
  • Manually tested

Screenshots

Fixes #253
Closes #254

  - Add smtp_username and smtp_password columns (migration v24)
  - Fix bug where SMTP password was collected but never persisted
  - Add SMTP Username field when 'Use same credentials as IMAP' is unchecked
  - buildSmtpConfig uses smtp_username/smtp_password with fallback to IMAP values
  - Refactor decryptAccountTokens to use ENCRYPTED_FIELDS loop
  - Add comprehensive test coverage for AddImapAccount (51 tests)
feat: support separate SMTP credentials (username + password)
Copilot AI review requested due to automatic review settings April 14, 2026 11:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for configuring separate SMTP credentials (username + password) for IMAP accounts, fixing a UI bug where the SMTP password field existed but was never persisted, and updating the DB + config-building logic to handle the new fields with backward-compatible fallbacks.

Changes:

  • Add DB columns smtp_username / smtp_password (migration v24) and plumb them through the DB account layer (insert + decrypt).
  • Update SMTP config building to prefer SMTP credentials with fallback to IMAP credentials.
  • Update the Add IMAP account UI to support SMTP username + “Use same credentials as IMAP”, and add new unit tests across UI/config/DB.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/test/mocks/entities.mock.ts Extends mock DbAccount objects with smtp_username/smtp_password.
src/services/imap/imapConfigBuilder.ts Uses SMTP username/password with fallback to IMAP/email.
src/services/imap/imapConfigBuilder.test.ts Adds tests covering separate SMTP credential fallback behavior.
src/services/db/migrations.ts Adds migration v24 to add smtp_username/smtp_password columns.
src/services/db/accounts.ts Extends DbAccount, refactors token decryption loop, and persists/encrypts SMTP password on insert.
src/services/db/accounts.test.ts Adds/updates tests verifying SMTP username/password persistence and decryption.
src/components/accounts/AddImapAccount.tsx Fixes SMTP password persistence, adds SMTP username field, and renames checkbox semantics to “same credentials”.
src/components/accounts/AddImapAccount.test.tsx Adds comprehensive UI tests including new separate SMTP credentials flow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/services/imap/imapConfigBuilder.ts
Comment thread src/components/accounts/AddImapAccount.tsx
Comment thread src/services/db/accounts.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/services/imap/imapConfigBuilder.ts Outdated
Comment thread src/components/accounts/AddImapAccount.tsx Outdated
Comment thread src/services/imap/imapConfigBuilder.ts
  - Revert username fallback to || (empty string is not a valid username)
  - Keep ?? for password fallback (empty string could be intentional)
  - Skip SMTP password validation for OAuth auth mode (avoids stuck state)
  - Update buildSmtpConfig docstring to note decryption requirement
  - Add edge case test: OAuth mode bypasses sameCredentials validation
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/services/db/accounts.ts Outdated
Comment thread src/components/accounts/AddImapAccount.test.tsx
Comment thread src/components/accounts/AddImapAccount.test.tsx
  - Narrow ENCRYPTED_FIELDS key type to specific string fields (removes unsafe cast)
  - Import ReactNode type instead of using React namespace
  - Restore crypto.randomUUID in afterEach to prevent test leaks
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/accounts/AddImapAccount.tsx Outdated
  Consistent with IMAP password validation. Checks trimmed value but stores
  the original to preserve intentional whitespace within passwords.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow separate username and password for outgoing (SMTP) server

2 participants