RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-email

error-invalid-email

Error message

Invalid email

What it means

`sendSMTPTestEmail` fetches the caller with `Meteor.userAsync()` and requires `user.emails[0].address` to exist; when the logged-in user has no (first) email address it throws `error-invalid-email`. The test mail needs a recipient, and the recipient is hard-wired to the caller's own primary email — there is no way to pass an alternative address.

Source

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

	// 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}`, {
				method: 'sendSMTPTestEmail',
				message,
			});
		}
		return {
			message: 'Sending_your_mail_to_s',

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Add an email address to the account (Profile, or Admin → Users) and retry the test.
  2. If users come from LDAP/OAuth, fix the field mapping so `mail`/email is populated on login.
  3. Verify beforehand with `GET /api/v1/users.info` that the target user has a non-empty `emails` array.
  4. Note the method only uses `emails[0]` — ensure the primary (first) email is the one you expect.

Example fix

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

// after - only offer the test when the caller has an email on file
const user = Meteor.user();
if (!user?.emails?.[0]?.address) {
  throw new Error('Add an email address to your profile before testing SMTP');
}
Meteor.call('sendSMTPTestEmail');
Defensive patterns

Strategy: type-guard

Validate before calling

const user = Meteor.user();
if (user?.emails?.[0]?.address) {
  await Meteor.callAsync('sendSMTPTestEmail');
} else {
  // prompt the user to add an email address first
}

Type guard

const hasPrimaryEmail = (user: { emails?: { address: string }[] } | null | undefined): user is { emails: { address: string }[] } =>
  !!user?.emails?.[0]?.address;

Try / catch

try {
  await Meteor.callAsync('sendSMTPTestEmail');
} catch (e: any) {
  if (e?.error === 'error-invalid-email') {
    // caller has no email on file: ask them to add one in profile settings
  }
}

Prevention

When it happens

Trigger: A logged-in user whose document has an empty/missing `emails` array or no `emails[0].address` invokes `sendSMTPTestEmail`. Typical for accounts provisioned without email: some LDAP mappings, OAuth providers that do not return an email, username-only accounts, or users created via API without an email field.

Common situations: LDAP field mapping not extracting mail; social/OAuth login without a verified email; test/demo users created without addresses; users whose email was removed by an admin.

Related errors


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