Skip to content
Merged
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
1 change: 1 addition & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type {
GenerateImageResult,
UploadFileParams,
UploadFileResult,
EmailAttachment,
SendEmailParams,
SendEmailResult,
ExtractDataFromUploadedFileParams,
Expand Down
59 changes: 54 additions & 5 deletions packages/sdk/src/modules/integrations.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ export interface UploadFileResult {
file_url: string;
}

/**
* A file to attach to an email.
*/
export interface EmailAttachment {
/**
* File name the recipient sees, including the extension. The supported extensions are `csv`, `docx`, `gif`, `ics`, `jpeg`, `jpg`, `md`, `pdf`, `png`, `txt`, `webp`, and `xlsx`.
*/
filename: string;
/**
* A file your app already uploaded, such as the `file_url` returned by [`UploadFile()`](#uploadfile) or the `file_uri` returned by [`UploadPrivateFile()`](#uploadprivatefile). Files uploaded by other apps are rejected.
*/
file_url?: string;
/** Base64-encoded file contents, for a file your code generated. */
content?: string;
}

/**
* Parameters for the SendEmail function.
*/
Expand All @@ -104,10 +120,18 @@ export interface SendEmailParams {
to: string;
/** Email subject line. */
subject: string;
/** Plain text email body content. */
body: string;
/** The name of the sender. If omitted, the app's name will be used. */
/** HTML email body. The same as `html`, so set one or the other, not both. */
body?: string;
/** HTML email body. The same as `body`, so set one or the other, not both. */
html?: string;
/**
* Plain-text email body. On its own, it sends a plain-text email. Set it together with `body` or `html` to send both versions in one email, and the recipient's mail client shows whichever it prefers. Make sure both versions say the same thing.
*/
text?: string;
/** The name of the sender. If omitted, the app's name is used. */
from_name?: string;
/** Files to attach. You can attach up to 5 files, up to 5 MB each and 10 MB in total. Set `filename` and exactly one of `file_url` or `content` on each file. */
attachments?: EmailAttachment[];
}

export type SendEmailResult = any;
Expand Down Expand Up @@ -257,10 +281,35 @@ export interface CoreIntegrations {
UploadFile(params: UploadFileParams): Promise<UploadFileResult>;

/**
* Send emails to registered users of your app.
* Send an email from your app.
*
* You can always email registered users of your app. To email anyone else, the app needs a paid plan and a connected custom domain.
*
* @param params - Parameters for sending email
* @param params - Parameters for sending email. Set at least one of `body`, `html`, or `text`.
* @returns Promise resolving when the email is sent.
*
* @example
* ```typescript
* // Send an HTML email with a plain-text version
* await base44.integrations.Core.SendEmail({
* to: "user@example.com",
* subject: "Your order has shipped",
* html: "<p>Your order <strong>#1234</strong> is on its way.</p>",
* text: "Your order #1234 is on its way.",
* });
* ```
*
* @example
* ```typescript
* // Attach a file your app uploaded
* const { file_url } = await base44.integrations.Core.UploadFile({ file });
* await base44.integrations.Core.SendEmail({
* to: "user@example.com",
* subject: "Your invoice",
* html: "<p>Your invoice is attached.</p>",
* attachments: [{ filename: "invoice.pdf", file_url }],
* });
* ```
*/
SendEmail(params: SendEmailParams): Promise<SendEmailResult>;

Expand Down
31 changes: 31 additions & 0 deletions packages/sdk/tests/types/integrations.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Base44Client } from "../../src/index.js";

declare const base44: Base44Client;

// Existing body-only callers keep compiling.
base44.integrations.Core.SendEmail({
to: "user@example.com",
subject: "Hello",
body: "<p>Hello</p>",
from_name: "My App",
});

// html and text each work alone, and together they send both versions.
base44.integrations.Core.SendEmail({ to: "user@example.com", subject: "Hello", text: "Hello" });
base44.integrations.Core.SendEmail({
to: "user@example.com",
subject: "Hello",
html: "<p>Hello</p>",
text: "Hello",
});

// An attachment is either an uploaded file or inline base64 content.
base44.integrations.Core.SendEmail({
to: "user@example.com",
subject: "Invoice",
html: "<p>See attached.</p>",
attachments: [
{ filename: "logo.png", file_url: "https://example.com/logo.png" },
{ filename: "invoice.pdf", content: "JVBERi0x" },
],
});
Loading