RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-email

error-invalid-email

Error message

Invalid email ${email}

What it means

Livechat.validateEmail delegates to validateEmail from @rocket.chat/tools and wraps failure in Meteor.Error('error-invalid-email', 'Invalid email ${email}'), echoing the offending value and function name in the details. It is used to validate email channel addresses when saving omnichannel visitor/contact data.

Source

Thrown at apps/meteor/server/lib/omnichannel/Helper.ts:958

			agentsId: agentsAdded,
		});
	}

	if (agentsUpdated.length > 0) {
		void notifyOnLivechatDepartmentAgentChangedByAgentsAndDepartmentId(agentsUpdated, departmentId);
	}

	if (agentsRemoved.length > 0 || agentsAdded.length > 0) {
		const numAgents = await LivechatDepartmentAgents.countByDepartmentId(departmentId);
		await LivechatDepartment.updateNumAgentsById(departmentId, numAgents);
	}

	return true;
};

export const validateEmail = (email: string) => {
	if (!validatorFunc(email)) {
		throw new Meteor.Error('error-invalid-email', `Invalid email ${email}`, {
			function: 'Livechat.validateEmail',
			email,
		});
	}
	return true;
};

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Send a fully qualified address (user@domain.tld) for visitor email channels
  2. Pre-validate with validateEmail from @rocket.chat/tools before calling the API
  3. For non-email channels, map identifiers to the matching channel type instead of email

Example fix

// before
visitor.emails = [phone]; // phone number stuffed into email field

// after
import { validateEmail } from '@rocket.chat/tools';
if (email && !validateEmail(email)) throw new Meteor.Error('error-invalid-email', `Invalid email ${email}`);
visitor.emails = [email];
Defensive patterns

Strategy: validation

Validate before calling

import { validateEmail } from '@rocket.chat/tools';
if (!validateEmail(email)) {
  throw new Meteor.Error('error-invalid-email', `Invalid email ${email}`, { email });
}

Try / catch

try {
  Livechat.validateEmail(email);
} catch (err) {
  if (err instanceof Meteor.Error && err.error === 'error-invalid-email') {
    // err.details.email holds the offending value; fix the input
  } else throw err;
}

Prevention

When it happens

Trigger: Passing 'nope', 'a@b' (no TLD per the validator), strings with spaces, or empty/undefined-ish values into livechat visitor email fields (visitor registration API, contact email channels).

Common situations: Channel integrations (SMS/WhatsApp) mapping phone numbers into email fields; forms without client-side validation; seed scripts using placeholder values like 'test'.

Related errors


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