RocketChat / RocketChat/Rocket.Chat
Bug RocketChat Email Inbox issue with mutated blocks in db even upon failure
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 46.1k
- Forks
- 13.9k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 130
Description
Description:
In the file located at apps/meteor/server/email-inbox/EmailInbox_Outgoing.ts . Before the email is confirmed sent. If SMTP fails, the message in the DB already shows the To: / Subject: context blocks as if the email was sent , but it was never delivered. So the message record in the database is updated to reflect a sent state regardless of whether the email was actually delivered.
- Bug Report
- Refactor Required
Steps to reproduce:
Prerequisites:
- A running RocketChat instance (tested on 8.3.0-develop)
- An SMTP test server running on localhost:1025 (e.g. maildev)
- Dovecot or equivalent IMAP server on localhost:143
- An Email Inbox configured in Admin then Email Inboxes with:
-
SMTP server: localhost, port: 1025, secure: false -
IMAP server: localhost, port: 143, secure: false -
Inbox active: true
reproduction:
Drop a raw email into the IMAP mailbox to trigger onEmailReceived:
sudo bash -c 'cat >> /var/mail/imaptest << EOF
From visitor@test.com Sat Mar 07 18:00:00 2026
From: visitor@test.com
To: test@example.com
Subject: Bug Test Room
Message-ID: <test-bug-001@test.com>
MIME-Version: 1.0
Content-Type: text/plain
This is the bug test email
EOF'
- Wait for RC to poll IMAP and create the room. Confirm in agent view
- room info must show Channel: Email not Channel: Livechat. If it shows Livechat, the room is not email-sourced and the bug will not trigger.
- Accept the conversation as an agent.
- Confirm SMTP is working by sending a test reply , verify if it arrives in MailDev UI at http://localhost:1080.
- Stop the SMTP server to simulate failure:
pkill -f maildev
-
In the agent view, hover over the incoming email message then click Reply then type any text then hit Send.
-
Observe in the RC server logs:
ERROR (EmailInbox): Error sending Email reply
message: "connect ECONNREFUSED ::1:1025"
code: "ESOCKET"
- Also observe the
rocket.caterror message appearing in the room:
@agent something went wrong when replying email, sorry. Error: connect ECONNREFUSED
// Using Node.js mongo client
const msgs = await db.collection('rocketchat_message')
.find({ rid: '<roomId>' },{ projection: { msg: 1, blocks: 1, _updatedAt: 1 } }).toArray();
Expected behavior:
since the email was never delivered, the message state in DB should remain unchanged from its pre-send state. The agent should be able to safely retry.
Actual behavior:
The replied message has blocks written with To: / Subject: context despite SMTP failure. The DB record reflects a "sent" state that never happened:
Server Setup Information:
- Version of Rocket.Chat Server: 8.3.0-develop
- License Type: Community (dev build)
- Number of Users: 1 (local dev)
- Operating System: Linux Debian bookworm (x86_64)
- Deployment Method: Source / yarn dev (Meteor development server)
- Number of Running Instances: 1
- NodeJS Version: 22.16.0
- MongoDB Version: 7.0.16 (wiredTiger engine)
Client Setup Information
- Desktop App or Browser Version: Chrome 145.0.0.0
- Operating System: Linux
Additional Issues Found :
Dead Code Double if (!inbox) Check
File: EmailInbox_Outgoing.ts afterSaveMessage callback
The second if (!inbox) block (line 165) is unreachable the first block at line 155 already returns if inbox is false.
if (!inbox) {
await sendErrorReplyMessage(...);
return message; // always returns here
}
if (!inbox) { // DEAD CODE, never reached
return message;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read apps/meteor/server/email-inbox/EmailInbox_Outgoing.ts, especially the afterSaveMessage callback, and reproduce the failure with SMTP unavailable as described. Done means a failed send leaves the message blocks and database state unchanged so the agent can retry, and the unreachable duplicate inbox check is addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100