RocketChat/Rocket.Chat · error · Error
error-invalid-email
Error message
error-invalid-email
What it means
While sending a data export by email, sendViaEmail iterates the recipient users (data.toUsers) and throws when a recipient's stored primary address (emails[0].address) fails Mailer.checkAddressFormat. One malformed address aborts the email for every recipient.
Source
Thrown at apps/meteor/server/lib/dataExport/sendViaEmail.ts:40
missing: string[];
}> {
const emails = data.toEmails.map((email) => email.trim()).filter(Boolean);
const missing = [...data.toUsers].filter(Boolean);
(
await Users.findUsersByUsernames(data.toUsers, {
projection: { 'username': 1, 'emails.address': 1 },
}).toArray()
).forEach((user: IUser) => {
const emailAddress = user.emails?.[0].address;
if (!emailAddress) {
return;
}
if (!Mailer.checkAddressFormat(emailAddress)) {
throw new Error('error-invalid-email');
}
const found = missing.indexOf(String(user.username));
if (found !== -1) {
missing.splice(found, 1);
}
emails.push(emailAddress);
});
const email = user.emails?.[0]?.address;
const lang = data.language || user.language || 'en';
const localMoment = moment();
if (lang !== 'en') {
const localeFn = await getMomentLocale(lang);
if (localeFn) {View on GitHub (pinned to b2c16d5842)
Solutions
- Identify the offending recipient: query the users in data.toUsers and format-check each emails[0].address
- Fix or clear the malformed address on the user profile (Administration > Users), or drop that recipient from the export
- Re-run the export once all recipient addresses are valid
Defensive patterns
Strategy: validation
Validate before calling
const users = await Users.findUsersByUsernames(data.toUsers, {
projections: { 'username': 1, 'emails.address': 1 },
}).toArray();
const invalid = users.filter((u) => {
const addr = u.emails?.[0]?.address;
return !addr || !Mailer.checkAddressFormat(addr);
});
if (invalid.length > 0) {
// report invalid usernames to the caller and exclude them before exporting
} Prevention
- Validate email format at user creation and import time (LDAP mapping, CSV import)
- Audit existing accounts for malformed primary addresses before enabling export-by-email
- Pre-filter recipients rather than letting one bad address abort the whole export
When it happens
Trigger: Calling sendViaEmail with data.toUsers containing a username whose user document has a syntactically invalid primary email — the loop hits the failing address and throws before any message is sent.
Common situations: Users provisioned from LDAP/SAML/CSV imports with unvalidated mail attributes; legacy accounts created before strict email validation; manual admin edits that stored malformed values.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/28ede9aac0a19294.
Report an issue: GitHub.