> For the complete documentation index, see [llms.txt](https://docs.mikopbx.com/mikopbx/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mikopbx.com/mikopbx/faq/cases/sending-an-incoming-fax-to-email.md).

# Отправка входящего факса на email

1. Добавьте новое приложение dialplan (см. [**Приложения диалпланов**](/mikopbx/manual/modules/dialplan-applications.md))

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FmIG0tKEPHkcJeemyctyM%2Fimage.png?alt=media&amp;token=55ab2ef3-17e6-4f69-aef4-84a9adfb984c" alt=""><figcaption><p>Новое приложение диалпланов</p></figcaption></figure>

2. Назначьте внутренний номер, к примеру **2200110**

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FabFhfZ1hI4O7Xm1YgLj1%2FNewDialplan.png?alt=media&amp;token=e48987df-3cae-48cd-ac62-26057626dd0f" alt=""><figcaption><p>Внутренний номер приложения</p></figcaption></figure>

3. Вставьте следующий код во вкладку "Программный код"

```php
<?php
require_once 'Globals.php';

use \MikoPBX\Core\Asterisk\AGI;
use MikoPBX\Core\System\Notifications;
use MikoPBX\Core\System\{MikoPBXConfig};

$agi     = new AGI();
$faxFile = "/tmp/" .$agi->get_variable("CDR(linkedid)", true).'.tiff';
$caller  = $agi->get_variable("CALLERID(num)", true);
$agi->exec("ReceiveFax", "{$faxFile},d"); 
$result  = $agi->get_variable("FAXOPT(status)", true);

if($result === 'SUCCESS' && file_exists($faxFile)){
    $notify = new Notifications();
    $notify->sendMail('test@gmail.com', 'Fax msg from '.$caller, 'Incoming fax <br><br>', $faxFile);
    unlink($faxFile);
}
sleep(1);
```

{% hint style="success" %}
В коде приложения укажите свой email вместо адреса «<test@gmail.com>».
{% endhint %}

4. Перейдите в раздел "**Кастомизация системных файлов**"

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FmRoCXGlTdLZsCYDSh3T2%2FcustomizationFiles.png?alt=media&amp;token=ec18b151-274a-4a56-9e51-17f693db0bb7" alt=""><figcaption><p>Раздел "Кастомизация системных файлов"</p></figcaption></figure>

5. Откройте для редактирования файл "**extensions.conf**"

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fgit-blob-0a1dd07707eb967d811042c18a85b2c567eb1916%2FextensionsConf%20(1).png?alt=media" alt=""><figcaption><p>Конфигурационный файл "extensions.conf"</p></figcaption></figure>

6. Добавьте следующий код в конец файла:

   ```php
   [SIP-1687941868-incoming](+)
   exten => fax,1,Goto(internal,2200100,1)
   ```

   «2200100» замените на номер **своего** приложения

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FeOyp7XLl3W1GoInaq6u7%2FCode.png?alt=media&amp;token=444c8495-0a1b-42f8-87aa-7f25cac1efa5" alt=""><figcaption><p>Код для extensions.conf</p></figcaption></figure>

В коде, «**SIP-1687941868**» замените на ID своего провайдера. Подсмотреть его значение можно в карточке провайдера, в адресной строке браузера

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FYjP21diTWeV0LJbGvgoy%2FProviderID.png?alt=media&amp;token=d5953dd8-6dfa-4c45-a1d0-b1f82041440d" alt=""><figcaption><p>ID провайдера</p></figcaption></figure>

7. Откройте для редактирования файл "**modules.conf**"

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Fs8dhNaf2xpdru73vq1BA%2FmodulesConf.png?alt=media&amp;token=ec6bd2e0-2d1a-4a5a-b49e-b3c693890ab8" alt=""><figcaption><p>Конфигурационный файл "Modules.conf"</p></figcaption></figure>

8. Вставьте в конец файла код:

```php
load => res_fax.so
load => res_fax_spandsp.so
```

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2FIKDdW6PEYNfMF5RjXLSo%2FCodeForModules.png?alt=media&amp;token=eccfdabc-5546-44ac-8954-37687e361b36" alt=""><figcaption><p>Код для modules.conf</p></figcaption></figure>

9. В карточке провайдера, в **расширенных настройках**, в **дополнительных параметрах** укажите

```php
[endpoint]
fax_detect=yes
fax_detect_timeout=30
```

<figure><img src="https://3704471835-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPK4TuzRBnP7rt8htho-887967055%2Fuploads%2Faz7HUIHEtwhZls1Mvf4b%2FcodeForProviders.png?alt=media&amp;token=92a333bb-534d-4019-9ff2-446f123f1219" alt=""><figcaption><p>Код в дополнительных параметрах провайдера</p></figcaption></figure>


---

# 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.mikopbx.com/mikopbx/faq/cases/sending-an-incoming-fax-to-email.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.
