RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

`sendSMTPTestEmail` starts with `if (!Meteor.userId())` and throws `error-invalid-user` when there is no authenticated DDP session. The method is intentionally available to any logged-in user (no permission check) because it only sends a test mail to the caller's own address — hence the login requirement is the sole gate.

Source

Thrown at apps/meteor/server/meteor-methods/settings/sendSMTPTestEmail.ts:21

import { Meteor } from 'meteor/meteor';

import * as Mailer from '../../lib/notifications/email/api';
import { settings } from '../../settings';

declare module '@rocket.chat/ddp-client' {
	// eslint-disable-next-line @typescript-eslint/naming-convention
	interface ServerMethods {
		sendSMTPTestEmail(): {
			message: string;
			params: string[];
		};
	}
}

Meteor.methods<ServerMethods>({
	async sendSMTPTestEmail() {
		if (!Meteor.userId()) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', {
				method: 'sendSMTPTestEmail',
			});
		}
		const user = await Meteor.userAsync();
		if (!user?.emails?.[0]?.address) {
			throw new Meteor.Error('error-invalid-email', 'Invalid email', {
				method: 'sendSMTPTestEmail',
			});
		}
		try {
			await Mailer.send({
				to: user.emails[0].address,
				from: settings.get('From_Email'),
				subject: 'SMTP Test Email',
				html: '<p>You have successfully sent an email</p>',
			});
		} catch ({ message }: any) {
			throw new Meteor.Error('error-email-send-failed', `Error trying to send email: ${message}`, {

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Log in first and only call the method once `Meteor.userId()` is set.
  2. For automated SMTP health checks, authenticate programmatically (token login) or run the check through an admin REST session.
  3. Handle the error as a signal to re-authenticate, then retry the send.

Example fix

// before
Meteor.call('sendSMTPTestEmail');

// after
if (!Meteor.userId()) {
  // require login before testing SMTP delivery
  return;
}
Meteor.call('sendSMTPTestEmail');
Defensive patterns

Strategy: validation

Validate before calling

if (!Meteor.userId()) {
  return;
}
await Meteor.callAsync('sendSMTPTestEmail');

Type guard

const isAuthenticated = (): boolean => typeof Meteor.userId() === 'string';

Try / catch

try {
  await Meteor.callAsync('sendSMTPTestEmail');
} catch (e: any) {
  if (e?.error === 'error-invalid-user') {
    // not logged in: authenticate, then retry the SMTP test
  }
}

Prevention

When it happens

Trigger: Calling `Meteor.call('sendSMTPTestEmail')` while unauthenticated: before login completes, after logout, with an expired resume token, or from server-side code without a user context.

Common situations: SMTP test button clicked from a stale logged-out tab; startup sequences that probe SMTP before authentication finishes; monitoring scripts invoking the DDP method without a session instead of using an authenticated REST call.

Understand the failure class

Background: error-invalid-user: "Invalid user" errors in Rocket.Chat — what they mean and how to fix them — this error's family across 2 libraries.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/db0d218ca79bdee4. Report an issue: GitHub.