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

# Email Domain Hooks

## What is an Email Sending Domain?

An email sending domain is a domain that you own and configure to send emails from your email marketing campaigns. It serves as the "From" address domain for your emails (e.g., if you send from `newsletter@yourdomain.com`, then `yourdomain.com` is your email sending domain).

### Why Use Email Sending Domains?

* **Improved Deliverability**: ISPs trust emails from verified domains more than generic sending services
* **Brand Recognition**: Recipients see emails coming from your branded domain
* **Authentication**: Enables proper SPF, DKIM, and DMARC authentication
* **Reputation Building**: Builds sender reputation tied to your domain rather than a shared service

### Domain Verification Process

Before you can send emails from a domain, it must be verified through DNS records to prove ownership and enable proper email authentication.

Simpu provides APIs to register and manage sending domains via the hooks defined below.

## useGetEmailDomains

The `useGetEmailDomains` hook fetches email domains, allowing you to retrieve a list of domains and their details.

<a target="_blank" href="https://tanstack.com/query/latest/docs/framework/react/reference/useQuery" className="border text-sm inline-block w-auto h-10 flex justify-self-start items-center justify-center text-center px-4 rounded-md border-gray-950/10 dark:border-white/10">
  <span>API Reference</span>
</a>

### Usage

```typescript theme={null}
import { useGetEmailDomains } from "@simpu/mail-sdk";

function SendingDomainsPage() {
  const { data, isPending, isError } = useGetEmailDomains();

  if (isPending) {
    return <div>Loading...</div>;
  }

  if (isError) {
    return <div>Error loading sending domains</div>;
  }

  return (
    <div>
      {data.map((domain) => (
        <div key={domain.id}>
          <h3>{domain.domain}</h3>
          <p>Status: {domain.status}</p>
        </div>
      ))}
    </div>
  );
}
```

## useEmailDomains

The `useEmailDomains` hook manages email domains including creation, verification, and deletion of domains.

### Usage

```typescript theme={null}
import { useEmailDomains } from "@simpu/mail-sdk";

function SendingDomainsComponent() {
  const { onCreateDomain, onVerifyDomain } = useEmailDomains();

  const handleCreateDomain = async (domainData: { domain: string }) => {
    const result = await onCreateDomain(domainData);
    if (result) {
      console.log("Domain created:", result);
    }
  };
}
```

### Return Values

* `onCreateDomain(payload: { domain: string })` - Creates a new email domain
* `onVerifyDomain(domainId: string)` - Verifies an email domain
