> For the complete documentation index, see [llms.txt](https://docs.uibakery.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uibakery.io/reference/data-sources/smtp.md). Agents can also search and read this documentation through its [MCP server](https://docs.uibakery.io/~gitbook/mcp).

# SMTP

## Configuration

To connect to an SMTP data source, follow the instruction below:

1. On the **Data sources** page, click **Connect**, and select *SMTP* in the Data sources list.
2. Give your data source a name and specify the required credentials:
   1. In the **Host** field, provide your server address.\
      \
      The SMTP server address typically looks like *smtp.example.com* or *mail.example.com*. For example, for Gmail the SMTP server address is usually `smtp.gmail.com`.<br>
   2. Next, determine the *port number*.\
      \
      SMTP servers usually listen on **port 25**. However, some providers may use alternative ports like *587* (submission) or *465* (SMTPS). You need to know the correct port number to establish the connection.
   3. Specify your *username* (for most SMTP providers, it should be your email address) and *password*.

{% hint style="warning" %}
Certain SMTP providers employ a multi-factor authentication process, so you might need a unique password exclusively for authenticating your UI Bakery application. Gmail SMTP requires [the creation of an app password](https://support.google.com/mail/answer/185833?hl=en) rather than your regular password.
{% endhint %}

3. Click **Test connection** to check whether the data source can be connected, and then click **Connect Datasource** to complete the setup.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2F1r6nfLVkFb8Zef9dd54u%2FCleanShot%202025-04-25%20at%2015.58.54%402x-min.png?alt=media&amp;token=2837af74-7951-450f-b952-1e510bf429ed" alt=""><figcaption></figcaption></figure>

## Usage

Once the data source is connected, you can start sending [SMTP Requests](https://docs.uibakery.io/reference/working-with-actions/smtp-request.md).

### Send email from an AI-generated app

Ask the agent to connect a new SMTP data source, or ask it to use an existing one by name. For a new connection, enter your SMTP credentials directly in the data source connection dialog. Keep passwords out of the chat.

Once the data source is connected to the project, ask the agent to create an action and wire it to a button. For example:

> Use the Company SMTP data source to add a Send email button. Show a confirmation after the SMTP server accepts the message, and show the error if sending fails.

The generated HTTP action uses `POST /send` with `bodyType: 'object'` and `body: '{{params.message}}'`. In your app, call the generated action with `useMutateAction` from `@uibakery/data` and pass the email fields inside `message`.

```typescript
import { useMutateAction } from '@uibakery/data';
import sendEmail from '@/actions/sendEmail';

export default function SendEmailButton() {
  const [send, sending, error] = useMutateAction(sendEmail);

  async function handleSend() {
    await send({
      message: {
        from: 'notifications@example.com',
        to: 'recipient@example.com',
        subject: 'Your report',
        text: 'The report is attached.',
        attachments: [
          {
            filename: 'report.txt',
            path: 'data:text/plain;base64,SGVsbG8=',
          },
        ],
      },
    });
  }

  return (
    <>
      <button type="button" onClick={handleSend} disabled={sending}>
        Send email
      </button>
      {error && <p role="alert">{String(error)}</p>}
    </>
  );
}
```

Supply at least one recipient in `to`, `cc`, or `bcc`. Each field accepts a comma-separated string of email addresses. You can also set `replyTo` and provide a plain-text body in `text`, an HTML body in `html`, or both.

Each attachment must contain a `filename` and a `path` containing a data URI. Convert browser `File` objects to data URLs before calling the action. The SMTP action accepts data URIs for attachments. Local paths and remote URLs are unsupported.

Use the action result to show whether the SMTP server accepted or rejected recipients. The result includes delivery metadata such as the message ID. SMTP acceptance confirms that the server accepted the message for delivery.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.uibakery.io/reference/data-sources/smtp.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
