Files
twenty/packages
sonarly-bot d983cb2ee3 fix(emails): resolve reply account from thread channel
https://sonarly.com/issue/38255?type=bug

Reply/compose can send with the wrong connected account ID, which triggers a pre-send validation error saying SMTP is not configured even when the user-configured account has SMTP.

Fix: Implemented a targeted frontend fix in the reply account selection path.

### What changed

1. **Resolved reply account from thread channel (not first account)**
   - Updated `useEmailThread` to query `myMessageChannels` (`GET_MY_MESSAGE_CHANNELS`) in addition to `myConnectedAccounts`.
   - Extracted `lastMessageChannelId` from the thread’s `MessageChannelMessageAssociation`.
   - Mapped that channel to its `connectedAccountId`.
   - Resolved `connectedAccount` by matching `connectedAccountId` in `myConnectedAccounts`.
   - Returned `connectedAccountId`, `connectedAccountHandle`, and `connectedAccountProvider` from this resolved account.
   - Kept loading behavior by combining both query loading states into `messageChannelLoading`.

   This removes the incorrect `myConnectedAccounts[0]` fallback that caused false SMTP-not-configured errors when the first account was not the thread’s send account.

2. **Added regression test**
   - Added `useEmailThread` unit test under existing email hooks test folder.
   - Test sets up:
     - two connected accounts (first is wrong),
     - message channel mapping where the thread’s channel points to the second account.
   - Asserts hook returns the second account’s ID/handle/provider, proving account resolution follows the thread channel rather than list order.

### Existing-fix check performed

I checked recent history before editing:
- `git log --all --oneline --since='30 days ago' -- <affected files>` returned no candidate fix for these files.
- Proceeded with implementation accordingly.

Authored by Sonarly by autonomous analysis (run 43673).
2026-05-18 08:01:32 +00:00
..
2026-05-04 11:09:34 +02:00