MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / validateEmailMessage

Function validateEmailMessage

apps/api/src/lib/email/email.utils.ts:77–99  ·  view source on GitHub ↗
(
  message: IEmailMessage,
  from: string
)

Source from the content-addressed store, hash-verified

75 * with a helpful field name so the error handler maps cleanly to a 400.
76 */
77export const validateEmailMessage = (
78 message: IEmailMessage,
79 from: string
80): void => {
81 if (!isValidEmail(message.to)) {
82 throw ApiErrors.validation(
83 `Invalid recipient email: ${maskEmailForLogging(message.to)}`,
84 "to"
85 );
86 }
87
88 if (!isValidEmail(from)) {
89 throw ApiErrors.internal(`Invalid sender email configured: ${from}`);
90 }
91
92 if (message.subject.trim().length === 0) {
93 throw ApiErrors.validation("Email subject is required", "subject");
94 }
95
96 if (message.html.trim().length === 0) {
97 throw ApiErrors.validation("Email HTML body is required", "html");
98 }
99};
100
101/*
102 * ---------------------------------------------------------------------------

Callers 6

sendMethod · 0.90
sendMethod · 0.90
sendMethod · 0.90
sendMethod · 0.90
sendMethod · 0.90

Calls 2

isValidEmailFunction · 0.85
maskEmailForLoggingFunction · 0.85

Tested by

no test coverage detected