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

# Send Email

Send emails using Antryk Email Service with a secure, scalable, and developer-friendly API.

This endpoint allows you to send transactional emails, OTPs, notifications, or bulk emails by providing recipient details, subject, and content. Authentication is handled via headers, making the request more secure and aligned with modern API standards.

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://ses.antryk.com/api/v1/email/send \
    --header "Content-Type: application/json" \
    --header "x-access-key: YOUR_ACCESS_KEY" \
    --header "x-secret-key: YOUR_SECRET_KEY" \
    --data '{
      "from": "admin@example.com",
      "to": ["ds1@gmail.com", "ds2@gmail.com"],
      "subject": "Otp For Antryk Sign up",
      "html": "<h1>Welcome</h1><p>Your OTP code: 123456</p>",
      "replyTo": "support@example.com",
      "attachments": [
        {
          "filename": "invoice.pdf",
          "content": "<base64-encoded-content>"
        }
      ]
    }'
  ```

  ```javascript JavaScript theme={null}
  fetch("https://ses.antryk.com/api/v1/email/send", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "x-access-key": "YOUR_ACCESS_KEY",
      "x-secret-key": "YOUR_SECRET_KEY",
    },
    body: JSON.stringify({
      from: "admin@example.com",
      to: ["ds1@gmail.com", "ds2@gmail.com"],
      subject: "Otp For Antryk Sign up",
      html: "<h1>Welcome</h1><p>Your OTP code: 123456</p>",
      replyTo: "support@example.com",
      attachments: [
        {
          filename: "invoice.pdf",
          content: "<base64-encoded-content>",
        },
      ],
    }),
  });
  ```

  ```javascript NodeJs theme={null}
  // npm i @antryk/sdk
  import { AntrykClient } from "@antryk/sdk";

  const client = new AntrykClient({
    accessKey: process.env.ANTRYK_ACCESS_KEY,
    secretKey: process.env.ANTRYK_SECRET_KEY,
  });

  async function sendEmail() {
    const result = await client.email.send({
      from: "admin@example.com",
      to: ["ds1@gmail.com", "ds2@gmail.com"],
      subject: "Otp For Antryk Sign up",
      html: "<h1>Welcome</h1><p>Your OTP code: 123456</p>",
      replyTo: "support@example.com",
      attachments: [
        {
          filename: "invoice.pdf",
          content: "<base64-encoded-content>",
        },
      ],
    });

    console.log(result.data);
  }

  sendEmail();
  ```

  ```python Python theme={null}
  # pip install requests
  import requests

  url = "https://ses.antryk.com/api/v1/email/send"

  headers = {
      "Content-Type": "application/json",
      "x-access-key": "YOUR_ACCESS_KEY",
      "x-secret-key": "YOUR_SECRET_KEY"
  }

  data = {
      "from": "admin@example.com",
      "to": ["ds1@gmail.com", "ds2@gmail.com"],
      "subject": "Otp For Antryk Sign up",
      "html": "<h1>Welcome</h1><p>Your OTP code: 123456</p>",
      "replyTo": "support@example.com",
      "attachments": [
          {
              "filename": "invoice.pdf",
              "content": "<base64-encoded-content>"
          }
      ]
  }

  response = requests.post(url, headers=headers, json=data)

  print(response.status_code)
  print(response.json())
  ```
</CodeGroup>

<Note>
  {" "}

  For Node.js applications, it is recommended to use the official
  [`@antryk/sdk`](https://www.npmjs.com/package/@antryk/sdk). The SDK simplifies
  email sending by handling authentication, validation, and error handling
  internally.{" "}
</Note>

<Note>
  {" "}

  Authentication is handled via headers (`x-access-key`, `x-secret-key`). The
  request body should only contain email-related fields such as sender,
  recipient, subject, and content.{" "}
</Note>

### New Email Sending Approach (Recommended)

This is the recommended and modern approach for sending emails:

* Authentication is passed via headers instead of request body.
* Request body contains only email-related fields.
* Cleaner, more secure, and easier to maintain.

<Note>
  {" "}

  ⚠️ The older approach (sending `accessKey` and `secretKey` in the body) may
  still work for backward compatibility, but it is **strongly recommended to
  migrate to header-based authentication**.{" "}
</Note>

## Request Parameters

<ParamField header="x-access-key" type="string" required>
  {" "}

  Your Antryk access key used for authentication.{" "}
</ParamField>

<ParamField header="x-secret-key" type="string" required>
  {" "}

  Your Antryk secret key used for authentication.{" "}
</ParamField>

<ParamField body="from" type="string" required>
  {" "}

  The sender's email address.{" "}
</ParamField>

<ParamField body="to" type="string | array" required>
  {" "}

  The recipient's email address. Can be a single email or an array for multiple
  recipients.{" "}
</ParamField>

<ParamField body="subject" type="string" required>
  {" "}

  The subject line of the email.{" "}
</ParamField>

<ParamField body="html" type="string">
  {" "}

  The HTML content of the email body.{" "}
</ParamField>

<ParamField body="text" type="string">
  {" "}

  Plain text version of the email body (fallback if HTML is not supported).{" "}
</ParamField>

<ParamField body="replyTo" type="string">
  {" "}

  Optional reply-to email address. Useful for directing responses to a support
  or no-reply inbox.{" "}
</ParamField>

<ParamField body="attachments" type="array">
  {" "}

  Optional list of attachments. Each item must include: - `filename`: Name of
  the file - `content`: Base64-encoded file content{" "}
</ParamField>

<Tip>
  {" "}

  You can send emails to multiple recipients by passing an array in the `to`
  field: `["user1@example.com", "user2@example.com"]`{" "}
</Tip>

<Warning>
  {" "}

  Either `html` or `text` must be provided when sending an email. At least one
  is required.{" "}
</Warning>

## Examples

<ParamField header="x-access-key" type="string" required> **Example:** `YOUR_ACCESS_KEY` </ParamField> <ParamField header="x-secret-key" type="string" required> **Example:** `YOUR_SECRET_KEY` </ParamField> <ParamField body="from" type="string" required> **Example:** `admin@example.com` </ParamField> <ParamField body="to" type="string | array" required> **Example:** `ds1@gmail.com` or `["ds1@gmail.com", "ds2@gmail.com"]` </ParamField> <ParamField body="subject" type="string" required> **Example:** `Otp For Antryk Sign up` </ParamField> <ParamField body="html" type="string"> **Example:** `<h1>Welcome to Antryk</h1><p>This is your OTP code: 123456</p>` </ParamField> <ParamField body="text" type="string"> **Example:** `Welcome to Antryk. This is your OTP code: 123456` </ParamField> <ParamField body="replyTo" type="string"> **Example:** `support@example.com` </ParamField> <ParamField body="attachments" type="array"> **Example:** `[{"filename": "invoice.pdf", "content": "<base64>"}]` </ParamField>

<Note>
  {" "}

  ### Additional Notes Supports transactional emails, OTP delivery, and bulk

  messaging. Attachments must be base64 encoded before sending. Ensure proper
  email formatting to improve deliverability. Avoid exposing API keys in
  frontend applications. SDK usage is recommended for better error handling and
  validation.{" "}
</Note>

## Response

Returns a JSON object confirming the email was sent successfully.

```json theme={null}
{
  "success": true,
  "messageId": "msg_123456",
  "to": "ds1@gmail.com",
  "subject": "Otp For Antryk Sign up"
}
```
