{"record":{"id":"1de0bfcfca9426a3","repo":"TryGhost/Ghost","slug":"the-server-did-not-receive-a-valid-email","errorCode":null,"errorMessage":"The server did not receive a valid email","messagePattern":"The server did not receive a valid email","errorType":"validation","errorClass":"ValidationError","httpStatus":422,"severity":"error","filePath":"ghost/core/core/server/api/endpoints/utils/validators/input/automated_emails.js","lineNumber":131,"sourceCode":"        validateOptionalStringField(senderName, 'Sender name must be a string');\n        validateOptionalStringField(senderEmail, 'Sender email must be a string');\n        validateOptionalStringField(senderReplyTo, 'Reply-to email must be a string');\n    },\n    verifySenderUpdate(apiConfig, frame) {\n        if (typeof frame.data.token !== 'string' || !frame.data.token.trim()) {\n            throw new ValidationError({\n                message: tpl(messages.tokenRequired)\n            });\n        }\n    },\n    preview(apiConfig, frame) {\n        validatePreviewData(frame);\n    },\n    sendTestEmail(apiConfig, frame) {\n        const email = frame.data.email;\n\n        if (typeof email !== 'string' || !validator.isEmail(email)) {\n            throw new ValidationError({\n                message: tpl(messages.invalidEmailReceived)\n            });\n        }\n\n        validatePreviewData(frame);\n    }\n};\n","sourceCodeStart":113,"sourceCodeEnd":139,"githubUrl":"https://github.com/TryGhost/Ghost/blob/47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe/ghost/core/core/server/api/endpoints/utils/validators/input/automated_emails.js#L113-L139","documentation":"Thrown by the `sendTestEmail` validator when `frame.data.email` is not a string or fails `validator.isEmail`. Before sending a test email, Ghost validates the recipient address format; an invalid address yields a 422 ValidationError with `invalidEmailReceived`. After this check, `validatePreviewData` also runs.","triggerScenarios":"A send-test-email request omits `email`, sends a non-string, or sends a syntactically invalid email address (missing `@`, bad domain, stray characters).","commonSituations":"Frontend submits before validating the email input; typo in the address; payload uses wrong key; empty string; user-provided address not sanitized.","solutions":["Validate the email address format client-side (regex or `validator.isEmail`) before sending.","Ensure the `email` field is present and a non-empty valid string in the request body.","Trim whitespace from the input before validation."],"exampleFix":"// before\nawait api.email.sendTestEmail({data: {email: 'not-an-email', subject, lexical}});\n\n// after\nawait api.email.sendTestEmail({data: {email: 'user@example.com', subject, lexical}});","handlingStrategy":"validation","validationCode":"import validator from '@tryghost/validator';\nfunction isValidEmail(v: unknown): boolean {\n    return typeof v === 'string' && validator.isEmail(v);\n}\nif (!isValidEmail(payload.email)) {\n    throw new Error('email must be a valid email address');\n}","typeGuard":"function isValidEmail(v: unknown): v is string {\n    return typeof v === 'string' && /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(v);\n}","tryCatchPattern":null,"preventionTips":["Validate the email format client-side before sending a test email.","Trim whitespace and confirm the `email` field is present in the payload.","Use the same validator library Ghost uses to match server-side behavior."],"tags":["api","validation","email","automated-emails","test-email"],"backgroundTag":null,"analyzedSha":"47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe","analyzedAt":"2026-08-13T01:25:26.651Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}