Skip to content

fix: Show error message when SMTP is not configured#38546

Open
SnehaChauhan1174 wants to merge 5 commits intoRocketChat:developfrom
SnehaChauhan1174:fix/smtp-check-before-mail
Open

fix: Show error message when SMTP is not configured#38546
SnehaChauhan1174 wants to merge 5 commits intoRocketChat:developfrom
SnehaChauhan1174:fix/smtp-check-before-mail

Conversation

@SnehaChauhan1174
Copy link
Copy Markdown

@SnehaChauhan1174 SnehaChauhan1174 commented Feb 7, 2026

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

fixes #38543

Summary by CodeRabbit

  • Bug Fixes

    • Email sending now validates SMTP configuration before attempting delivery and surfaces a clear, actionable error when SMTP is not fully configured, preventing silent or failed send attempts.
  • Chores

    • No changes to public interfaces or external behavior beyond the improved SMTP validation.

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Feb 7, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 7, 2026

⚠️ No Changeset found

Latest commit: d695ba4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 7, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 7, 2026

No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1740223 and d695ba4.

📒 Files selected for processing (1)
  • apps/meteor/app/mailer/server/api.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/app/mailer/server/api.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer

Walkthrough

Adds a runtime SMTP configuration check inside the mailer send flow: when MAIL_URL is not set, the code inspects SMTP host/port/username/password from settings and throws a smtp-not-configured Meteor.Error if any required field is missing. Also a minor whitespace adjustment.

Changes

Cohort / File(s) Summary
Mailer SMTP runtime check
apps/meteor/app/mailer/server/api.ts
Added runtime SMTP configuration validation when MAIL_URL is absent (reads SMTP_Host, SMTP_Port, SMTP_Username, SMTP_Password from settings and computes isIncompleteSMTP); throws Meteor.Error('smtp-not-configured') if incomplete. Removed an extra blank line after the IPreEmailSent trigger.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I sniff the mailer, twitch my nose,
I check the hosts where smtp-wind blows,
If ports or creds are gone from view,
I cry "smtp-not-configured" true,
Hopping off — now errors tell what's due 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding SMTP configuration validation and error messaging in the mailer API.
Linked Issues check ✅ Passed The code changes implement SMTP configuration validation with clear error messages before sending mail, fulfilling the objective in issue #38543.
Out of Scope Changes check ✅ Passed The changes are limited to SMTP validation logic in the sendNoWrap function with a minor formatting adjustment, remaining within the scope of issue #38543.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/meteor/app/mailer/server/api.ts`:
- Around line 161-167: The block that retrieves SMTP_Host uses spaces for
indentation instead of tabs, causing a style mismatch; locate the smtpHost
assignment and the subsequent if/throw that uses
settings.get<string>('SMTP_Host') and Meteor.Error, and re-indent those lines
with tabs to match the file's existing tab-based formatting so
linting/formatters no longer flag the diff.
🧹 Nitpick comments (1)
apps/meteor/app/mailer/server/api.ts (1)

163-166: Consider using an i18n key instead of a hardcoded English string for the user-facing error reason.

The second argument to Meteor.Error is surfaced to end-users. Other parts of this file use i18n.t(key, { lng }) for translated strings. A hardcoded English sentence won't be translated for non-English deployments.

That said, existing Meteor.Error calls in this file (e.g., 'invalid email' on Line 159) also use plain strings, so this is consistent with the current pattern — worth addressing holistically rather than just here.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb366e7 and 6ec6ede.

📒 Files selected for processing (1)
  • apps/meteor/app/mailer/server/api.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/mailer/server/api.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🔇 Additional comments (1)
apps/meteor/app/mailer/server/api.ts (1)

161-167: No action needed. The setting key SMTP_Host is correctly registered in the settings registry at apps/meteor/server/settings/email.ts and is used consistently throughout the codebase with matching identifiers.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread apps/meteor/app/mailer/server/api.ts Outdated
Comment on lines +161 to +167
const smtpHost = settings.get<string>('SMTP_Host');
if (!smtpHost) {
throw new Meteor.Error(
'smtp-not-configured',
'SMTP is not configured. Please configure it in Administration -> Settings -> Email -> SMTP before sending emails.',
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Indentation mismatch: uses 4 spaces instead of tabs.

Lines 161–167 are indented with spaces while the rest of the file consistently uses tabs. This will cause linting/formatting failures or at minimum a noisy diff.

🔧 Proposed fix — re-indent with tabs to match the file
-    const smtpHost = settings.get<string>('SMTP_Host');
-    if (!smtpHost) {
-        throw new Meteor.Error(
-            'smtp-not-configured',
-            'SMTP is not configured. Please configure it in Administration -> Settings -> Email -> SMTP before sending emails.',
-        );
-    }
+	const smtpHost = settings.get<string>('SMTP_Host');
+	if (!smtpHost) {
+		throw new Meteor.Error(
+			'smtp-not-configured',
+			'SMTP is not configured. Please configure it in Administration -> Settings -> Email -> SMTP before sending emails.',
+		);
+	}

As per coding guidelines, "Write concise, technical TypeScript/JavaScript" — the formatting should be consistent with the rest of the file.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const smtpHost = settings.get<string>('SMTP_Host');
if (!smtpHost) {
throw new Meteor.Error(
'smtp-not-configured',
'SMTP is not configured. Please configure it in Administration -> Settings -> Email -> SMTP before sending emails.',
);
}
const smtpHost = settings.get<string>('SMTP_Host');
if (!smtpHost) {
throw new Meteor.Error(
'smtp-not-configured',
'SMTP is not configured. Please configure it in Administration -> Settings -> Email -> SMTP before sending emails.',
);
}
🤖 Prompt for AI Agents
In `@apps/meteor/app/mailer/server/api.ts` around lines 161 - 167, The block that
retrieves SMTP_Host uses spaces for indentation instead of tabs, causing a style
mismatch; locate the smtpHost assignment and the subsequent if/throw that uses
settings.get<string>('SMTP_Host') and Meteor.Error, and re-indent those lines
with tabs to match the file's existing tab-based formatting so
linting/formatters no longer flag the diff.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="apps/meteor/app/mailer/server/api.ts">

<violation number="1" location="apps/meteor/app/mailer/server/api.ts:161">
P2: New SMTP_Host-only check blocks valid email configurations that rely on MAIL_URL; use the existing isSMTPConfigured logic instead of hard-requiring SMTP_Host.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread apps/meteor/app/mailer/server/api.ts Outdated
@TheRazorbill
Copy link
Copy Markdown
Contributor

Hi @SnehaChauhan1174 ! Let's fix the administrative blocks first:

  1. PR Title: Please rename the PR to fix: Show error message when SMTP is not configured. The current format is triggering the Invalid PR Title label.

How to fix: You can change the title by clicking the "Edit" button at the top of this page (to the right of the current title or in checks). Please follow the Conventional Commits format.

  1. CLA: It seems you've signed it, but it's still showing as pending.

How to fix: Try clicking the 'recheck' link in the CLAassistant comment. You can also go to the checks list at the bottom of the page, click on "license/cla", and ensure everything is authorized.

Once these are green, we can look into the linting and logic issues!

@SnehaChauhan1174 SnehaChauhan1174 changed the title fix (mailer): shows error message when smtp is not configured fix (mailer): Show error message when SMTP is not configured Feb 22, 2026
@SnehaChauhan1174 SnehaChauhan1174 changed the title fix (mailer): Show error message when SMTP is not configured fix: Show error message when SMTP is not configured Feb 22, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ec6ede and 1740223.

📒 Files selected for processing (1)
  • apps/meteor/app/mailer/server/api.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/mailer/server/api.ts
🧠 Learnings (2)
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.

Applied to files:

  • apps/meteor/app/mailer/server/api.ts
📚 Learning: 2025-09-19T15:15:04.642Z
Learnt from: rodrigok
Repo: RocketChat/Rocket.Chat PR: 36991
File: apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts:219-221
Timestamp: 2025-09-19T15:15:04.642Z
Learning: The Federation_Matrix_homeserver_domain setting in apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts is part of the old federation system and is being deprecated/removed, so configuration issues with this setting should not be flagged for improvement.

Applied to files:

  • apps/meteor/app/mailer/server/api.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/meteor/app/mailer/server/api.ts`:
- Around line 163-168: isSMTPConfigured currently returns true if
settings.get('SMTP_Host') or process.env.MAIL_URL is present, but that allows
incomplete credentials; update the isSMTPConfigured function so it returns true
only when there is either a valid MAIL_URL OR all required SMTP settings are
present and non-empty (at minimum check SMTP_Host, SMTP_Port, SMTP_Username,
SMTP_Password and any TLS flag like SMTP_UseTLS if your code expects it), and
keep the guard around the throw in the same block that calls isSMTPConfigured
(the code that throws 'smtp-not-configured' in api.ts). If you parse MAIL_URL,
validate it contains auth and host:port; otherwise ensure
settings.get('SMTP_Host'), settings.get('SMTP_Port'),
settings.get('SMTP_Username'), and settings.get('SMTP_Password') are truthy
before allowing Email.sendAsync to run.

---

Duplicate comments:
In `@apps/meteor/app/mailer/server/api.ts`:
- Around line 162-168: The new SMTP check block uses spaces (and mixed
space+tab) instead of the file's tab indentation; update the if-block that calls
isSMTPConfigured() and the nested throw new Meteor.Error(...) so each line uses
tabs (no spaces) and matches the surrounding tab-based indentation style,
removing any mixed whitespace to satisfy lint/format rules.

Comment thread apps/meteor/app/mailer/server/api.ts Outdated
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.

4 participants