{"record":{"id":"28ede9aac0a19294","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-email-28ede9","errorCode":null,"errorMessage":"error-invalid-email","messagePattern":"error-invalid-email","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/dataExport/sendViaEmail.ts","lineNumber":40,"sourceCode":"\tmissing: string[];\n}> {\n\tconst emails = data.toEmails.map((email) => email.trim()).filter(Boolean);\n\n\tconst missing = [...data.toUsers].filter(Boolean);\n\n\t(\n\t\tawait Users.findUsersByUsernames(data.toUsers, {\n\t\t\tprojection: { 'username': 1, 'emails.address': 1 },\n\t\t}).toArray()\n\t).forEach((user: IUser) => {\n\t\tconst emailAddress = user.emails?.[0].address;\n\n\t\tif (!emailAddress) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (!Mailer.checkAddressFormat(emailAddress)) {\n\t\t\tthrow new Error('error-invalid-email');\n\t\t}\n\n\t\tconst found = missing.indexOf(String(user.username));\n\t\tif (found !== -1) {\n\t\t\tmissing.splice(found, 1);\n\t\t}\n\n\t\temails.push(emailAddress);\n\t});\n\n\tconst email = user.emails?.[0]?.address;\n\tconst lang = data.language || user.language || 'en';\n\n\tconst localMoment = moment();\n\n\tif (lang !== 'en') {\n\t\tconst localeFn = await getMomentLocale(lang);\n\t\tif (localeFn) {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/dataExport/sendViaEmail.ts#L22-L58","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const users = await Users.findUsersByUsernames(data.toUsers, {\n  projections: { 'username': 1, 'emails.address': 1 },\n}).toArray();\nconst invalid = users.filter((u) => {\n  const addr = u.emails?.[0]?.address;\n  return !addr || !Mailer.checkAddressFormat(addr);\n});\nif (invalid.length > 0) {\n  // report invalid usernames to the caller and exclude them before exporting\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["email","data-export","validation"],"backgroundTag":"invalid-email-address","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}