{"record":{"id":"8d33784390b067ed","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-email-8d3378","errorCode":"error-invalid-email","errorMessage":"Invalid email","messagePattern":"Invalid email","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/settings/sendSMTPTestEmail.ts","lineNumber":27,"sourceCode":"\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tsendSMTPTestEmail(): {\n\t\t\tmessage: string;\n\t\t\tparams: string[];\n\t\t};\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync sendSMTPTestEmail() {\n\t\tif (!Meteor.userId()) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'sendSMTPTestEmail',\n\t\t\t});\n\t\t}\n\t\tconst user = await Meteor.userAsync();\n\t\tif (!user?.emails?.[0]?.address) {\n\t\t\tthrow new Meteor.Error('error-invalid-email', 'Invalid email', {\n\t\t\t\tmethod: 'sendSMTPTestEmail',\n\t\t\t});\n\t\t}\n\t\ttry {\n\t\t\tawait Mailer.send({\n\t\t\t\tto: user.emails[0].address,\n\t\t\t\tfrom: settings.get('From_Email'),\n\t\t\t\tsubject: 'SMTP Test Email',\n\t\t\t\thtml: '<p>You have successfully sent an email</p>',\n\t\t\t});\n\t\t} catch ({ message }: any) {\n\t\t\tthrow new Meteor.Error('error-email-send-failed', `Error trying to send email: ${message}`, {\n\t\t\t\tmethod: 'sendSMTPTestEmail',\n\t\t\t\tmessage,\n\t\t\t});\n\t\t}\n\t\treturn {\n\t\t\tmessage: 'Sending_your_mail_to_s',","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/settings/sendSMTPTestEmail.ts#L9-L45","documentation":"`sendSMTPTestEmail` fetches the caller with `Meteor.userAsync()` and requires `user.emails[0].address` to exist; when the logged-in user has no (first) email address it throws `error-invalid-email`. The test mail needs a recipient, and the recipient is hard-wired to the caller's own primary email — there is no way to pass an alternative address.","triggerScenarios":"A logged-in user whose document has an empty/missing `emails` array or no `emails[0].address` invokes `sendSMTPTestEmail`. Typical for accounts provisioned without email: some LDAP mappings, OAuth providers that do not return an email, username-only accounts, or users created via API without an email field.","commonSituations":"LDAP field mapping not extracting mail; social/OAuth login without a verified email; test/demo users created without addresses; users whose email was removed by an admin.","solutions":["Add an email address to the account (Profile, or Admin → Users) and retry the test.","If users come from LDAP/OAuth, fix the field mapping so `mail`/email is populated on login.","Verify beforehand with `GET /api/v1/users.info` that the target user has a non-empty `emails` array.","Note the method only uses `emails[0]` — ensure the primary (first) email is the one you expect."],"exampleFix":"// before\nMeteor.call('sendSMTPTestEmail');\n\n// after - only offer the test when the caller has an email on file\nconst user = Meteor.user();\nif (!user?.emails?.[0]?.address) {\n  throw new Error('Add an email address to your profile before testing SMTP');\n}\nMeteor.call('sendSMTPTestEmail');","handlingStrategy":"type-guard","validationCode":"const user = Meteor.user();\nif (user?.emails?.[0]?.address) {\n  await Meteor.callAsync('sendSMTPTestEmail');\n} else {\n  // prompt the user to add an email address first\n}","typeGuard":"const hasPrimaryEmail = (user: { emails?: { address: string }[] } | null | undefined): user is { emails: { address: string }[] } =>\n  !!user?.emails?.[0]?.address;","tryCatchPattern":"try {\n  await Meteor.callAsync('sendSMTPTestEmail');\n} catch (e: any) {\n  if (e?.error === 'error-invalid-email') {\n    // caller has no email on file: ask them to add one in profile settings\n  }\n}","preventionTips":["Ensure account provisioning (LDAP/OAuth mappings, API user creation) always sets emails[0].","Check hasPrimaryEmail before offering the SMTP test button.","Verify with users.info when diagnosing accounts created without email."],"tags":["meteor","smtp","email","user-profile"],"backgroundTag":"missing-user-email","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}