Messinet Secure Services
wiki:FAXGateway/Config/SendmailProcmail
Last modified 5 months ago Last modified on 01/04/12 11:09:18

FAX Gateway - Sendmail/Procmail Configuration

The simplest method available is to create a "fax.your-domain.com" sub domain in your internal DNS to which all outbound faxes are sent so Sendmail can route them to the fax-gw script via Procmail. The creation of the DNS sub domain is outside the scope of this document.

In this configuration, it is assumed that mail in "your-domain.com" is routed via DNS MX records and that your Asterisk server, asterisk.your-domain.com, is not on the same host as your mail gateway.

Sendmail Gateway

On the mail gateway, edit the following file to contain:

  • /etc/mail/mailtertable
    fax.your-domain.com smtp:[asterisk.your-domain.com]
    

Sendmail on the Asterisk Server

On the Asterisk server, edit the following files to contain:

  • /etc/mail/sendmail.mc
    LOCAL_DOMAIN(`fax.your-domain.com')dnl
    
  • /etc/mail/sendmail.cf
    C{w}fax.your-domain.com
    
  • /etc/mail/virtusertable
    @fax.your-domain.com asterisk
    

Procmail on the Asterisk Server

On the Asterisk server, edit the .procmailrc file of the asterisk user in the proper home directory.

  • ~asterisk/.procmailrc
    LOGFILE=$HOME/procmail.log
    FORMAIL = "/usr/bin/formail"
    #VERBOSE=on
    LOG="Logging ${LOGFILE} for ${LOGNAME}, "
    
    # This recipe will deliver faxes only if the sender has
    # authenticated through mail gateway for SMTP
    # or sent via our webmail
    
    ####
    
    :0
    * ^Received: from .*\(authenticated bits=0\) .*by mailserver\.your-domain\.com
    
    {
            :0
            {
    
    #Get the full To: address
             :0
             * ^To:[         ]*\/[^  ].*        {
                     TO_=$MATCH
             }
    
    }
    
             :0
             *
             {
    # Get the username portion of the To: address (Fax number to send to)
    RECIP_FAX_NUM=`echo "${TO_}" | awk -F@ '{ print $1 }'`
             }
    
             :0
             *        {
    # Get the sender's address, ignore Reply-To:
    SENDER_MAIL=`formail -I"Reply-To:" -rt -xTo: | expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`
                      }
    
    # Send the message to the AGI for fax processing
    :0
    *
    | /usr/share/asterisk/agi-bin/fax-gw/fax-gw.agi -s $SENDER_MAIL -t $RECIP_FAX_NUM
    }
    
    ###########
    
    # Mail sent to *@fax.your-domain.com from unauthenticated users gets thrown out
    # Sends a message back saying it must be authenticated.
    :0 c
    * ! ^Received: from .*\(authenticated bits=0\) .*by mailserver\.your-domain\.com
    #/dev/null
    
                     | (formail -rI"Precedence: junk" \
                          -A"X-Loop: [EMAIL PROTECTED]" ; \
                        echo "Your email was received by the Asterisk Fax Gateway."; \
                        echo ""; \
                        echo "However, you did not send your message through the authenticated mail SMTP server - so your fax will NOT be sent."; \
                        echo ""; \
                        echo "Please consult XXXX@your-domain.com for help"; \
                       ) | $SENDMAIL -oi -t -fpostmaster@your-domain.com
    
    :0
    *
    /dev/null