wcz-layout
Version:
54 lines (43 loc) • 1.36 kB
Markdown
# email
## Server
`import { ... } from "wcz-layout/data/server";`
- `sendEmail({ data: EmailSchema })` → `void` // server-only, call inside another server function
- `body` // HTML string
- `attachments` // `appName` + `subId` used when uploading the files (see [file.md](file.md)); the email service attaches all files stored under that `subId`
## Schemas/Models
```ts
const EmailSchema = z.object({
subject: z.string().trim().min(1).max(60),
body: z.string().trim().min(1),
to: z.array(z.email()).min(1),
bcc: z.array(z.email()).optional(),
cc: z.array(z.email()).optional(),
attachments: z.array(EmailAttachmentSchema).optional(),
});
const EmailAttachmentSchema = z.object({
appName: z.string().trim().min(1).max(100),
subId: z.uuid(),
});
```
## Examples
```ts
import { sendEmail } from "wcz-layout/data/server";
// inside another server function
await sendEmail({
data: {
subject: "Hello",
body: "<p>Hi</p>",
to: ["user@example.com"],
},
});
// with cc and attachments (files previously uploaded with uploadFileMutationOptions({ appName, subId, file }))
await sendEmail({
data: {
subject: "Document Submission",
body: "<p>Attached are the requested documents.</p>",
to: ["recipient@example.com"],
cc: ["team@example.com"],
attachments: [{ appName: packageJson.name, subId }],
},
});
```