Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export type SendEmailOptions = {
subject: string;
html?: string;
text?: string;
template?: string;
variables?: Record<string, string>;
replyTo?: string[];
headers?: { name: string; value: string }[];
};
Expand Down Expand Up @@ -271,7 +273,7 @@ export class Resend {

async sendEmailManually(
ctx: RunMutationCtx,
options: Omit<SendEmailOptions, "html" | "text">,
options: Omit<SendEmailOptions, "html" | "text" | "template" | "variables">,
sendCallback: (emailId: EmailId) => Promise<string>,
): Promise<EmailId> {
const emailId = (await ctx.runMutation(
Expand Down Expand Up @@ -367,6 +369,8 @@ export class Resend {
createdAt: number;
html?: string;
text?: string;
template?: string;
variables?: Record<string, string>;
} | null> {
return await ctx.runQuery(this.component.lib.get, {
emailId,
Expand Down
12 changes: 10 additions & 2 deletions src/component/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export const sendEmail = mutation({
html: v.optional(v.string()),
text: v.optional(v.string()),
replyTo: v.optional(v.array(v.string())),
template: v.optional(v.string()),
variables: v.optional(v.record(v.string(), v.string())),
headers: v.optional(
v.array(
v.object({
Expand All @@ -106,8 +108,8 @@ export const sendEmail = mutation({
}

// We require either html or text to be provided. No body = no bueno.
if (args.html === undefined && args.text === undefined) {
throw new Error("Either html or text must be provided");
if (args.html === undefined && args.text === undefined && args.template === undefined) {
throw new Error("Either html, text, or template must be provided");
}

// Store the text/html into separate records to keep things fast and memory low when we work with email batches.
Expand Down Expand Up @@ -140,6 +142,8 @@ export const sendEmail = mutation({
html: htmlContentId,
text: textContentId,
headers: args.headers,
template: args.template,
variables: args.variables,
segment,
status: "waiting",
complained: false,
Expand Down Expand Up @@ -607,6 +611,10 @@ async function createResendBatchPayload(
]),
)
: undefined,
template: email.template ? {
id: email.template,
variables: email.variables,
} : undefined,
}));

return [emails.map((e) => e._id), JSON.stringify(batchPayload)];
Expand Down
2 changes: 2 additions & 0 deletions src/component/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export default defineSchema({
replyTo: v.array(v.string()),
html: v.optional(v.id("content")),
text: v.optional(v.id("content")),
template: v.optional(v.string()),
variables: v.optional(v.record(v.string(), v.string())),
headers: v.optional(
v.array(
v.object({
Expand Down