RocketChat/Rocket.Chat · error · Meteor.Error

invalid email

invalid email

Error message

invalid email

What it means

Mailer.sendNoWrap (and Mailer.send, which delegates to it) validates every recipient with validateEmail from @rocket.chat/tools via checkAddressFormat before sending; if any 'to' address fails the format check it throws Meteor.Error('invalid email'). This is a pre-SMTP format check - the mail never reaches the transport. Arrays are checked with every(), so one malformed recipient fails the whole call.

Source

Thrown at apps/meteor/server/lib/notifications/email/api.ts:158

export const sendNoWrap = async ({
	to,
	from,
	replyTo,
	subject,
	html,
	text,
	headers,
}: {
	to: string | string[];
	from: string;
	replyTo?: string;
	subject: string;
	html?: string;
	text?: string;
	headers?: string;
}) => {
	if (!checkAddressFormat(to)) {
		throw new Meteor.Error('invalid email');
	}

	if (!text) {
		text = html ? stripHtml(html).result : undefined;
	}

	if (settings.get('email_plain_text_only')) {
		html = undefined;
	}

	const value = await Settings.incrementValueById('Triggered_Emails_Count', 1, { returnDocument: 'after' });
	if (value) {
		void notifyOnSettingChanged(value);
	}

	const email = { to, from, replyTo, subject, html, text, headers };

	const eventResult = await Apps.self?.triggerEvent(AppEvents.IPreEmailSent, { email });

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Log and inspect the exact 'to' value being sent; fix its format
  2. Pre-validate with Mailer.checkAddressFormat (or validateEmail from @rocket.chat/tools) before calling send
  3. Trim addresses and build 'Name <addr@domain>' only from verified, fully qualified fields

Example fix

// before
await Mailer.send({ to: user.emails[0], from, subject, html }); // object, not string

// after
const addr = user.emails?.[0]?.address?.trim() ?? '';
if (!Mailer.checkAddressFormat(addr)) throw new Error('bad recipient');
await Mailer.send({ to: addr, from, subject, html });
Defensive patterns

Strategy: validation

Validate before calling

import { Mailer } from '.../email/api';
const recipients = ([] as string[]).concat(to).map((a) => a.trim());
if (!Mailer.checkAddressFormat(recipients)) {
  // drop or fix bad recipients before sending
  throw new Error('invalid recipient');
}

Try / catch

try {
  await Mailer.send({ to, from, subject, html });
} catch (err) {
  if (err instanceof Meteor.Error && err.error === 'invalid email') {
    // log the 'to' value and fix its format; nothing was sent
  } else throw err;
}

Prevention

When it happens

Trigger: Mailer.send({ to: 'user@@example' }), to: '', to: ['ok@x.com', 'nope'], or an untrimmed address with spaces/newlines coming from stored user profile data.

Common situations: Unverified or typo'd user email addresses; passing user.emails[0] (an object) instead of .address; templating code injecting undefined into the address; addresses imported from LDAP/CSV with stray quotes or whitespace.

Related errors


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