> 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="/files/RgoY6Jmo0odu6yQW2ssR" alt=""><figcaption><p>Новое приложение диалпланов</p></figcaption></figure>

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

<figure><img src="/files/Eiyj8nwQxClqGK5DJ5ts" 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="/files/vijEVOA1rNRbdd8BCwSl" alt=""><figcaption><p>Раздел "Кастомизация системных файлов"</p></figcaption></figure>

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

<figure><img src="/files/VUuCfVqNcFcxZzAVl1oF" alt=""><figcaption><p>Конфигурационный файл "extensions.conf"</p></figcaption></figure>

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

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

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

<figure><img src="/files/P4d3ZPiEyVOS0X6GLNCk" alt=""><figcaption><p>Код для extensions.conf</p></figcaption></figure>

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

<figure><img src="/files/DPh1sE5vGqLSYotJAgDC" alt=""><figcaption><p>ID провайдера</p></figcaption></figure>

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

<figure><img src="/files/GQiq3WOyViHhrCpGdlky" alt=""><figcaption><p>Конфигурационный файл "Modules.conf"</p></figcaption></figure>

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

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

<figure><img src="/files/P4Rk7s7kyYtDhq4xCrNu" alt=""><figcaption><p>Код для modules.conf</p></figcaption></figure>

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

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

<figure><img src="/files/dsrkhrnNWVD5ImMasAgk" 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 dynamically by asking a question.

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

```
GET https://docs.mikopbx.com/mikopbx/faq/cases/sending-an-incoming-fax-to-email.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
