> ## Documentation Index
> Fetch the complete documentation index at: https://docs.emailux.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send with SendGrid and EmailUX

> Add a SendGrid domain to EmailUX, save your SendGrid API key, and render or deliver templates with @emailux/api-client.

A SendGrid domain gives you the full API: **`render()`** and **`deliver()`**.

**1. Authenticate your domain in SendGrid**

In SendGrid, authenticate the domain you will send from, so SPF and DKIM pass. See the [email authentication guide](https://www.emailux.com/guides/email-authentication).

**2. Add the domain in EmailUX**

Open **Emails, Providers and API Keys** and choose **Add domain (SendGrid)**. Enter your domain, such as `yourdomain.com`, and select **Create**.

**3. Configure the delivery provider**

In the domain card, open **Configure delivery provider**, select **SendGrid**, paste your SendGrid API key, and **Save**. The key is stored for this domain. Choose **Provider status** to confirm the connection.

**4. Add sender emails**

Add the sender addresses you will use, for example `hello@yourdomain.com`. When a provider is configured, the domain's API key is authorized for the domain, so each sender does not need separate verification.

**5. Enable templates for this domain**

A template is available on this domain after you enable it. On an email, choose **Set SendGrid domain**, or on the domain card choose **Manage templates** and add it. A template with no live version is not available until one is marked live.

**6. Generate an API key**

Select **Generate API key**. The domain must not be pending. See [API keys](https://docs.emailux.com/providers/api-keys.md).

**7. Call the API**

```ts theme={null}
import { EmailUxApiClient } from '@emailux/api-client';

const client = new EmailUxApiClient({
  apiKey: process.env.EMAILUX_API_KEY!,
  sendgridDomain: 'yourdomain.com',
});

const sent = await client.deliver({
  experienceId: 'welcome_email',
  channelData: {
    toEmail: 'alex@example.com',
    fromEmail: 'hello@yourdomain.com',
    fromEmailName: 'Your product',
  },
  data: { nameTo: 'Alex' },
});
```

## Removing a domain

Deleting a domain also removes its provider configuration, all of its API keys and all of its sender emails. You confirm by typing `Delete yourdomain.com`. This cannot be undone.

## Troubleshooting

> [accordion] Generate API key is disabled
>
> The domain is still pending. Finish the domain verification, then try again.

> [accordion] I get a 502 provider error
>
> SendGrid rejected the request. Check that the saved key has mail-send permission and that the sender uses your authenticated domain.

> [accordion] I get a 401
>
> The API key is wrong or revoked. Generate a new one.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.