{"record":{"id":"a26fc11d14c3aa0a","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-email-a26fc1","errorCode":"error-invalid-email","errorMessage":"Invalid email ${email}","messagePattern":"Invalid email (.+?)","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/validateEmailDomain.js","lineNumber":40,"sourceCode":"\t\t.split(',')\n\t\t.filter(Boolean)\n\t\t.map((domain) => domain.trim());\n});\nsettings.watch('Accounts_AllowedDomainsList', (value) => {\n\tif (!value) {\n\t\temailDomainWhiteList = [];\n\t\treturn;\n\t}\n\n\temailDomainWhiteList = value\n\t\t.split(',')\n\t\t.filter(Boolean)\n\t\t.map((domain) => domain.trim());\n});\n\nexport const validateEmailDomain = async function (email) {\n\tif (!validateEmail(email)) {\n\t\tthrow new Meteor.Error('error-invalid-email', `Invalid email ${email}`, {\n\t\t\tfunction: 'RocketChat.validateEmailDomain',\n\t\t\temail,\n\t\t});\n\t}\n\n\tconst emailDomain = email.substr(email.lastIndexOf('@') + 1);\n\n\tif (emailDomainWhiteList.length && !emailDomainWhiteList.includes(emailDomain)) {\n\t\tthrow new Meteor.Error('error-invalid-domain', 'The email domain is not in whitelist', {\n\t\t\tfunction: 'RocketChat.validateEmailDomain',\n\t\t});\n\t}\n\tif (\n\t\temailDomainBlackList.length &&\n\t\t(emailDomainBlackList.indexOf(emailDomain) !== -1 ||\n\t\t\t(settings.get('Accounts_UseDefaultBlockedDomainsList') && emailDomainDefaultBlackList.indexOf(emailDomain) !== -1))\n\t) {\n\t\tthrow new Meteor.Error('error-email-domain-blacklisted', 'The email domain is blacklisted', {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/validateEmailDomain.js#L22-L58","documentation":"validateEmailDomain() runs a syntactic check (validateEmail) on every email address handed to server flows such as user creation, invites and email changes; a malformed address (bad format, missing '@') throws error-invalid-email with the offending value in details.email. This is the first gate before the domain whitelist/blacklist/DNS checks that follow in the same function.","triggerScenarios":"Server code passing a non-email string to RocketChat.validateEmailDomain(email); invites or user-creation calls whose address has no '@', multiple '@'s, or spaces; CSV import rows with dirty email columns reaching user creation.","commonSituations":"Client forms without email validation; import pipelines that never sanitize the email column; string-concatenation bugs producing addresses like 'user@@example.com'.","solutions":["Validate and normalize the address before calling (trim + email regex, or a library like validator.isEmail).","Fix the source data (form or import file) that produced the malformed address.","Re-run the invite/creation once the address is corrected."],"exampleFix":"// before\nawait validateEmailDomain('not-an-email');\n\n// after\nconst email = 'user@example.com'.trim();\nif (!/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email)) throw new Error('malformed email');\nawait validateEmailDomain(email);","handlingStrategy":"validation","validationCode":"const EMAIL_RE = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\nconst isEmailShape = (v: string): boolean => EMAIL_RE.test(v.trim());\n\nif (!isEmailShape(email)) throw new Error(`malformed email: ${email}`);\nawait validateEmailDomain(email.trim());","typeGuard":"const isWellFormedEmail = (v: unknown): v is string =>\n  typeof v === 'string' && /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(v.trim());","tryCatchPattern":"try {\n  await validateEmailDomain(email);\n} catch (err: any) {\n  if (err?.error === 'error-invalid-email') {\n    // flag the specific address (err.details.email) back to the user; do not retry unchanged\n    return reportInvalidAddress(err.details?.email);\n  }\n  throw err;\n}","preventionTips":["Validate at the form/API boundary with trim + regex before user creation or invites.","Sanitize CSV import rows (drop/repair malformed emails) before they reach the server.","Remember the whitelist/blacklist/DNS checks only run after this syntactic gate passes."],"tags":["email","validation","user-management"],"backgroundTag":"email-validation-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}