Sending an incoming fax to email

  1. Add a new dialplan application (see Dialplan Applications).

  1. Assign an internal number, for example, 2200110.

  1. Insert the following code into the "Programme Code" tab:

<?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('your-email@gmail.com', 'Fax msg from '.$caller, 'Incoming fax <br><br>', $faxFile);
    unlink($faxFile);
}
sleep(1);

In the code, replace 'your-email@gmail.com' with your own email address.

  1. Go to the "System file customization" section.

  1. Open the "extensions.conf" file for editing.

  1. Add the folowwing code to the end of file:

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

Replace "2200100" with the number of your application.

In the code, replace "SIP-1687941868" with your provider's ID. You can find it in the provider's card in the browser's address bar.

  1. Open the "modules.conf" file for editing.

  1. Add the following code to the end of the file:

load => res_fax.so
load => res_fax_spandsp.so
  1. In the provider's card, in the advanced settings, in additional parameters, specify:

[endpoint]
fax_detect=yes
fax_detect_timeout=30

Last updated