Hello william wu,
sorry for the delayed reply. Here are some snippets on how I've implemented that feature. But as it is a complex setup, it will not work with copy & paste, the information provided will be guideline and the shows the parts related to FusionPBX and the triggers in the MTA.
Postfix:
/etc/postfix/main.cf
Code:
transport_maps = pcre:/etc/postfix/transport_maps.pcre
mailtofax_destination_recipient_limit = 1
/etc/postfix/transport_maps.pcre
Code:
/^\d{3}\d+@fax.*/ mailtofax
/etc/postfix/master.cf
Code:
mailtofax unix - n n - 2 pipe
flags= user=vmail:www-data argv=/usr/local/bin/mailtofax.sh ${mailbox} ${sender}
/usr/local/bin/mailtofax.sh
Code:
#!/bin/sh
set -x
LOGFILE=/tmp/mailtofax_$(date +'%Y%m%d_%H%M%S')_$$.log
echo -n "faxmail was called: " > ${LOGFILE}
echo "date: $(date +'%Y/%m/%d %H:%M:%S'); pid: $$" >> ${LOGFILE}
echo "Phone Nr.: ${1}," "Sender: ${2}" >> ${LOGFILE}
#Modify Subject to contain the [Fax] tag & Phone Nr.
sed -e "s/Subject:/Subject: [Fax][${1}] /" <&0 | /usr/sbin/sendmail <&0 ${2}
echo "exit status sendmail: $? \n" >> ${LOGFILE}
if echo $? ; then
echo "Calling /var/www/fusionpbx/app/fax/fax_emails.php:" >> ${LOGFILE}
/usr/bin/php /var/www/fusionpbx/app/fax/fax_emails.php 2>&1 >> ${LOGFILE}
echo "\n/var/www/fusionpbx/app/fax/fax_emails.php finished." >> ${LOGFILE}
fi
root
Just to give you a rough overview what will happen there with the above config:
Any mail reaching the postfix MTA with a delivery address of "3 or more numerical digits"@fax will be handled by the mailtofax transport. The transport is effectively a script which is called with $mailbox and $sender as argument.
And that transport does not much in this setup. It just adds [FAX][fax-number] to the Subject and sends it via sendmail back to the $sender. Further the FusionPBX provided fax_emails.php is called. This php script then checks the configured mailboxes for new faxes and picks up the fax into the FusionPBX fax sending queue.
The flow of the email is:
sender -> fax-number@fax (only numerical digits allowed, submitted via smtp to postfix)
postfix -> mailtofax.sh -> sender (submitted via localhost)
postfix receives the new mail with the updated subject directed to the sender itself
That's where dovecot comes into action with a Sieve filter & a hidden Fax directory in the users mailbox:
/etc/dovecot/conf.d/90-sieve.conf
Code:
sieve_default = /var/lib/dovecot/sieve/default.sieve
/var/lib/dovecot/sieve/default.sieve
Code:
require ["fileinto"];
if address :contains "to" "@fax" {
fileinto "Fax";
}
FusionPBX is configured at the web-interface to connect to dovecot via IMAP & look into the folder FAX for new faxes, with the prefix [FAX] [FAX-Number]. fax_emails.php triggers FusionPBX to do that lookup and the sending of the fax.
Postfix is configured to do a SASL auth with Dovecot, mailboxes are virtual mailboxes, and Dovecot gets the user data from the FusionPBX database.
conf.d/auth-sql.conf.ext
Code:
driver = sql
args = /etc/dovecot/dovecot-sql.conf.ext
/etc/dovecot/dovecot-sql.conf.ext
Code:
driver = pgsql
connect = host=localhost dbname=fusionpbx user=fusionpbx password='database-password'
default_pass_scheme = PLAIN
password_query = SELECT extension AS user, password \
FROM v_extensions WHERE extension = '%n';
user_query = SELECT '/var/vmail/%n' AS home, 'vmail' AS gid, \
'vmail' AS uid FROM v_extensions WHERE extension = '%n';
With that SQL connection, any extension configured in FusionPBX can connect to the SMTP server with the username = extension & password = extension_password.
In this case a quick-setup-standalone PBX with mail2fax available was the goal, no user scheme integration required. The mail2fax sender has to setup a dedicated e-mail account for faxing on his client device.
Strongly depending on what your goal is, it might be a complete nonsense to do that SQL connection in the described way.
I hope that you could get some idea on how to eventually handle mail2fax in connection with FusionPBX. Mailing is a complex topic, and has a lot of additional configuration which have not been outlined here.
Best regards,
Harald