How to: Pipe Email to a Script or Program Using Qmail

Email pipes can be used to send all messages meant for a specific email address to a program, or script. This is commonly used when an external program, such as a help desk ticketing software or customer relationship management software, will handle emails without intervention by a user.

To Pipe Email Using Qmail

  1. Log in to the server at the CLI as root, either via SSH or from the terminal

  2. At the CLI, navigate to the mail folder for the domain. The mail folder is located at /home/{unixuser}/var/{domain.com}/mail, replacing {unixuser} and {domain.com} with the correct corresponding user and domain

    cd /home/{unixuser}/var/{domain.com}/mail
    
  3. Using a text editor, create a file named .qmail-{receiving_username}. Where {receiving_username} represents the part of the email address before the @. For example, if all email directed to sales@domain.com should be handled by the external program/script, the file would be named .qmail-sales. The following example uses the vim text editor

    vim .qmail-{receiving_username}
    
  4. In the text editor, add the following, replacing {unixuser}, {domain.com}, {script_path} with the correct corresponding user, domain, and script path:

    |php -q /home/{unixuser}/{domain.com}/html/{script_path}
    

    Note

    The software vendor’s documentation should provide the script path to use.

  5. Save the changes, and quit the text editor

  6. Update the permissions on the file so that it is owned as vpopmail:{unixuser}, replacing {unixuser} with the correct corresponding user

    chown vpopmail:{unixuser} /home/{unixuser}/var/{domain.com}/mail/.qmail-{receiving_username}