# Send email

{% tabs %}
{% tab title="Shell" %}

```sh
curl https://api.acymailer.com/api/send \
 -X POST \
 -H 'Content-Type: application/json' \
 -H 'API-KEY: your-license-key' \
 -H 'Version: external' \
 -d '{"email":"Date: Thu, 7 Mar 2024 12:15:03 +0100\r\nFrom: Email example <email@example.com>\r\nCc: cc@recipients.com\r\nReply-To: Email no-reply <no-reply@example.com>\r\nMessage-ID: <fFkkPmogsPGI9joSa6txvJno0DBX20VhMQgu6Hk6Q@rleclercq-A027-I00000>\r\nX-Mailer: PHPMailer 6.9.1 (https:\/\/github.com\/PHPMailer\/PHPMailer)\r\nMIME-Version: 1.0\r\nContent-Type: multipart\/alternative;\r\n boundary=\"b1=_fFkkPmogsPGI9joSa6txvJno0DBX20VhMQgu6Hk6Q\"\r\nContent-Transfer-Encoding: 8bit\r\nTo: email@recipients.com\r\nSubject: This is the subject\r\n\r\n--b1=_fFkkPmogsPGI9joSa6txvJno0DBX20VhMQgu6Hk6Q\r\nContent-Type: text\/plain; charset=us-ascii\r\n\r\nThis is the alternative body. Only text here\r\n\r\n--b1=_fFkkPmogsPGI9joSa6txvJno0DBX20VhMQgu6Hk6Q\r\nContent-Type: text\/html; charset=us-ascii\r\n\r\nThis is the body with a <h1>title<\/h1> and a <a href=\"https:\/\/www.acymailing.com\">link<\/a>.\r\n\r\n\r\n--b1=_fFkkPmogsPGI9joSa6txvJno0DBX20VhMQgu6Hk6Q--\r\n","domainsUsed":["example.com"]}'
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
  
$acymailer = new AcyMailer\SendingService('your-license-key');

$optionsSendEmail = [
    'to' => 'email@recipients.com',
    'subject' => 'This is the subject',
    'body' => 'This is the body with a <h1>title</h1> and a <a href="https://www.acymailing.com">link</a>.',
    'alt_body' => 'This is the alternative body. Only text here', // optionnal
    'from_email' => 'email@example.com',
    'from_name' => 'Email example',
    'reply_to_email' => 'no-reply@example.com', // optional, default to from_email
    'reply_to_name' => 'Email no-reply', // optional, default to from_name
    'bounce_email' => 'bounce@example.com', // optional, default to from_email
    'cc' => ['cc@recipients.com'], // optional, must be an array
    'attachments' => ['/path/to/attachment.png'], // optional, must be an array
];

$response = $acymailer->send($optionsSendEmail);
```

{% endtab %}

{% tab title="Node" %}

```javascript
import {AcyMailer} from '@acymailing/sending-service';

const mailer = new AcyMailer('your-license-key');

const email = {
    to: 'email@recipients.com',
    subject: 'test email from node lib',
    body: '<h1>Hello</h1>, this is a test email from the node lib', // altBody?: string,
    fromEmail: 'email@example.com',
    fromName: 'Email example',
    replyToEmail: 'no-reply@example.com',
    replyToName: 'Email no-reply',
    bounceEmail: 'bounce@example.com', // cc?: string[];
    attachments: [
        '/paht/to/attachment.png'
    ]
};

const response = await mailer.sendEmail(email);
```

{% endtab %}
{% endtabs %}

<mark style="color:green;">`POST`</mark> `/api/send`

Send an email with the API

**Headers**

| Name         | Value                |
| ------------ | -------------------- |
| Content-Type | `application/json`   |
| API-KEY      | `<license-key>`      |
| Version      | `Must be "external"` |

**Body**

```json
{
    "email":"Date: Thu, 7 Mar 2024 12:15:03 +0100\r\nFrom: Email example <email@example.com>\r\nCc: cc@recipients.com\r\nReply-To: Email no-reply <no-reply@example.com>\r\nMessage-ID: <fFkkPmogsPGI9joSa6txvJno0DBX20VhMQgu6Hk6Q@rleclercq-A027-I00000>\r\nX-Mailer: PHPMailer 6.9.1 (https:\/\/github.com\/PHPMailer\/PHPMailer)\r\nMIME-Version: 1.0\r\nContent-Type: multipart\/alternative;\r\n boundary=\"b1=_fFkkPmogsPGI9joSa6txvJno0DBX20VhMQgu6Hk6Q\"\r\nContent-Transfer-Encoding: 8bit\r\nTo: email@recipients.com\r\nSubject: This is the subject\r\n\r\n--b1=_fFkkPmogsPGI9joSa6txvJno0DBX20VhMQgu6Hk6Q\r\nContent-Type: text\/plain; charset=us-ascii\r\n\r\nThis is the alternative body. Only text here\r\n\r\n--b1=_fFkkPmogsPGI9joSa6txvJno0DBX20VhMQgu6Hk6Q\r\nContent-Type: text\/html; charset=us-ascii\r\n\r\nThis is the body with a <h1>title<\/h1> and a <a href=\"https:\/\/www.acymailing.com\">link<\/a>.\r\n\r\n\r\n--b1=_fFkkPmogsPGI9joSa6txvJno0DBX20VhMQgu6Hk6Q--\r\n",
    "domainsUsed":["example.com"],
    "isTransactional": false
}
```

* **email** must be your email in a MIME format&#x20;
* **domainUsed** must be an array of all domains used in the email for the the 3 email addresses:\
  \- From email\
  \- Bounce email\
  \- Reply-to email
* **isTransactional** must be either true or false

For example:

&#x20;Same domain but different email addresses:\
\- **From**: <marketing@your-domain.com>\
\- **Reply-to**: <no-reply@your-domain.com>\
\- **Bounce**: <bounce@your-domain.com>\
The value should be `["your-domain.com"]`

Different domain and different email addresses:\
\- **From**: <marketing@your-domain.com>\
\- **Reply-to**: <no-reply@your-domain.com>\
\- **Bounce**: <bounce@your-other-domain.com>\
The value should be `["example.com", "your-other-domain.com"]`

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
    "code": 22,
    "message": "Email sent!"
}
```

{% endtab %}

{% tab title="400" %}

```json
// Unknown error 
{
    "code": 2,
    "message": "An error occurred, see details in the sending service logs file in the configuration",
    "logs": "<details>"
}

// No email in the body of the request
{
    "code": 16,
    "message": "The email is missing"
}

// Unknown error
{
    "code": "<details>",
    "message": "An error occurred, please see details in the browser console",
    "logs": "<details>"
}
```

{% endtab %}

{% tab title="404" %}

```json
// Domain not found
{
    "code": 20,
    "message": "Domain not found: %s",
    "messageData": "[\"<domain-missing>\"]"
}

// The domain exist but is not attached for this license
{
    "code": 20,
    "message": "No domain found for this licence"
}
```

{% endtab %}

{% tab title="403" %}

```json
// License under verification
{
    "code": 15,
    "message": "Your license is under verification because we detected an unsafe content in your previously sent email"
}

// License blocked
{
    "code": 15,
    "message": "Your license is blocked"
}

// No credits left on your license
{
    "code": 18,
    "message": "No credits left"
}

// Error when handling credits when sending email
{
    "code": 7,
    "message": "An error related to the remaining credits occurred when trying to send an email"
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.acymailing.com/acymailer/send-email.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
