osTicket – Plesk 9 – Postfix – Pipe mail to a program or script

Another day, another dent in the wall. And yet my head remains intact…

I’m currently installing osTicket for my most complex server. With 3 sites (and more in the pipeline), thousands of users and what is normally a complex task list of internal support requests, it’s been on my mind that I need to have as support desk system running. Primarily for us to manage the internal support and development tasks, but also so the site administrators can have a more efficient way of dealing with user support requests rather than the somewhat slapdash forum that’s in use currently.

So I researched the various open source options out there.

There are a bunch of thing to consider when choosing a support system that I won’t go into here, but if you are looking into it, here’s a good place to start:
TechRepublic.com | 10 things to consider when choosing a help desk system [new window]

With these considerations in mind, my key requirements were:
Open Source
PHP/MySQL driven
Email & Web interface

The system that I chose then was osTicket as it seems to fulfil these requirements. And their website didn’t look like shit. Call me shallow, but I never trust software supplied by someone who has an ugly website with bad UI. There really should be a symbiotic relationship between your ability to create functional software, and present it. If you can’t design and code a good site, it’s less likely that your software will be any good – especially when it’s a web application!

Installation is straight forward and painless – typical web based configuration script. Quite happy with that. Then it gets a little more complex.

[Update] I later notice that osTicket is available for installation via the Plesk Application Vault. How well this works, I don’t know. Can’t say I trust the Plesk interface do do much at the moment![/Update]

In order for emails to be processed by the software, you need to be able to pipe it to the osTicket script. To do that you need one of two things – cPanel or root access.
cPanel, while limited in certain ways, has some really good features – like the ability to set up email pipes without needing root access. osTicket’s wiki even tells you how to do this:
osTicket wiki | Email Piping [new window]

Plesk by contrast can be incredibly powerful, but omits such simple functionality, so a little more knowledge is required. Luckily the process isn’t too painful, if you don’t balls it up. Plesk uses postfix mail server by default – if you use something different DO NOT follow these instructions. They won’t work!
To check if you have Postfix, look for a /etc/postfix folder.
File locations may vary dependant on OS flavour and if you don’t use Plesk.
The instructions are provided as is and without warranty of any sort. Y’know – be careful! I knocked out the mail server for an entire night without realising, which is why I’m trying to share the benefit of my errors, but don’t blame me if you do worse.
Read the instructions through fully before continuing, and proceed with caution.

You will be creating a pipe command with a unique name. You can name it what you want. I called mine pipeSupportEmail. In the following instructions I use the placeholder {pipeName}. Be sure to use your unique name to replace all instances.

Step 1

SSH in to your server.
Back up main.cf for postfix and then edit it. I use VI.
There should be a copy of main.cf.default, but this probably won’t match your working version.

# cp /etc/postfix/main.cf /etc/postfix/main.cf.bak# vi /etc/postfix/main.cf

Find ‘transport_maps’. To do this in vi, hit [esc] to enter command mode and type

/transport_maps

and hit [return].
Note: There is only one incidence of this in the file, but if you ever need to repeat a search in VI, just hit /[return]

You need to add to the line an option ‘hash:/var/spool/postfix/plesk/{pipeName}’, so after editing it should read:

transport_maps = hash:/var/spool/postfix/plesk/transport, hash:/var/spool/postfix/plesk/{pipeName}

Note: This MUST be all on ONE line
If you have multiple pipes you will enter them all consecutively, so if you had three line might look like this:

transport_maps = hash:/var/spool/postfix/plesk/transport, hash:/var/spool/postfix/plesk/{pipeName}, hash:/var/spool/postfix/plesk/{pipeNameB}, hash:/var/spool/postfix/plesk/{pipeNameC}

Again, this would be all on ONE line.

Once done, save and quit – (in VI [esc]:wq[return])

Step 2

Create a new file /var/spool/postfix/plesk/{pipeName}
This is a transport_map file and will direct all mail sent to your chosen addresses into the pipe (see, the internet really is a series of tubes…)

# vi /var/spool/postfix/plesk/{pipeName}

Add all the email addresses that should be piped to your software in the following format:

{address}@{domain.tld} {pipeName}:{logDescription}{address}@{domain.tld} {pipeName}:{logDescription}

Where {logDescription} is a note for the mail log. Make this meaningful and unique – then you can easily search the log for it, and distinguish the messages.

So a file might read:

support@company.com pipeSuportEmailt:osTicket support pipedinternalsupport@company.com pipeSuportEmail:osTicket internalsupport pipedsales@company.com pipeSuportEmail:osTicket sales piped

Save and close the file.

With these rules in place I can search my mail log later for osTicket to check whether mail is being piped.

Step 3

Hash the file we just created as postfix wants a database file to work with

postmap /var/spool/postfix/plesk/{pipeName}

If you run ‘ls /var/spool/postfix/plesk/’ you will see there is now a file called {pipeName}.db

Step 4

The last step of coding is to tell postfix which script or program all the email will be piped to, by editing master.cf. Kinda important I suppose…
Oh yeah – BACKUP FIRST!

# cp /etc/postfix/master.cf /etc/postfix/master.cf.bak# vi /etc/postfix/master.cf

Search for ‘plesk_saslauthd’, and on the NEXT line, enter the following ALL ON ONE LINE:

{pipeName} unix - n n - - pipe flags=Fq user=apache:apache argv={pathToPipe} ${sender}

{pathToPipe} is the path to the script you want to pipe to. In the case of osTicket this will probably be /var/www/vhosts/{domain}/httpdocs/{osTicketLocation}/api/pipe.php
Again, {domain} and {osTicketLocation} will depend on your installation.
IMPORTANT: {sender} is NOT to be replaced – it is the script variable ${sender}, being the email address the message was sent from
IMPORTANT: Ensure the are NO spaces after ${sender} or postfix will throw it’s toys out of the pram.

If you have multiple pipes to different scripts or programs, enter each one on a new line.

Step 5

Restarting postfix seems like the easiest part of the process, but if you have made a mistake, it doesn’t complain much, so first, open a new SSH terminal, and tail your mail logfile so you can see if any errors are thrown:

# tail -f /usr/local/psa/var/log/maillog

This will watch the tail of the file, and you will see activity logged as it happens.
The name and location of your maillog may vary if you are using a different version of Plesk, or not using Plesk at all.

Now you can restart postfix

# postfix reload

If it complains that postfix is not running, you can try ‘postfix start’ instead, but if postfix isn’t running, you have another problem with you mail server, and it might not start – look to the mail log for information on what’s going wrong.

These instructions based on Nexology Community | Creating Email Pipe with Plesk 9.2.2 [new window]

[Update]Oh dear, it doesn’t seem to work yet.

From the maillog:

Oct 1 14:10:39 serverXXX-XX pipe[9594]: fatal: pipe_command: execvp /var/www/vhosts/{domain}.com/subdomains/support/httpdocs/api/pipe.php: Permission deniedOct 1 14:10:39 serverXXX-XX postfix/pipe[9088]: EF2541117B5: to=<support@{domain}.com>, relay=pipeSupportEmails, delay=3.5, delays=3.4/0/0/0.02, dsn=4.3.0, status=deferred (temporary failure. Command output: pipe: fatal: pipe_command: execvp /var/www/vhosts/{domain}.com/subdomains/support/httpdocs/api/pipe.php: Permission denied )

This is not an uncommon error, but none of the suggested solutions I have found online yet resolve it. I will update when I have more idea.
It would seem (perhaps obviously) to just be a matter of setting the permissions correctly, but I’ve clearly not worked out just how they should be set.[/Update]

Piping with qmail

If your setup uses qmail rather than postfix, these instructions may help. BE WARNED – I have not tested this:

Do this for each address that you wish to be piped to osTicket

# vi /var/qmail/mailnames/yourdomain.com/{address@domain.com}/.qmail

Where {address@domain.com} is the address you are receiving mail to – e.g. support@somecompany.com

Add the following as the FIRST line of the file:

| php -q /var/www/vhosts/{domain}/httpdocs/{osTicketLocation}/api/pipe.php

Save and quit.
Restart qmail

# service qmail restart

Hmm. I’m jealous now… That looks really simple.

[Update 4-10-2010]I’ve also found this advice on Plesk with qmail:

Plesk, Email Piping/Email Pipe (osTicket / Trellis) | Steve Jameson [new window]

 

[Updatae 7-10-2015]
Risen from the grave!
In response to a comment, it is worth pointing out a reply I made to another comment a long time ago:

To set permission, EVERY folder in the path to pipe,php must be chmod o+x
I also had to chmod o+x api.inc.php

chmod 755 will do the same thing. The commenter also had to do the same to pipe.php, though I don’t recall having had to do that at the time, and that server doesn’t even exist any more to check…

15 thoughts on “osTicket – Plesk 9 – Postfix – Pipe mail to a program or script”

  1. No problem! Haven’t actually got the piping working yet though, but this is likely a Plesk/postfix issue so will be updating as soon as I have.

  2. Hey, I got this working! Thanks so much. All I needed to do was create the mail account in Plesk, but without a mailbox, and I used the user who "owned" my site, so basically I looked at who owned the files in the httpdocs folder and went:{pipeName} unix – n n – – pipe flags=Fq user={userWhoOwnsSite} argv={Etc…}And then the permissions are sweet. At least for me. I did chmod +x the script file in question.

  3. Hi Peter – thanks for the input!I’ve currently used the qMail route, as even postfix seems to use the qmail file structure, and it seems to work. I’ve now got an issue with PHP crapping out due to a Plesk update, but that is completely seperate. I promise I will be updating with my results when I can get back to this, but have been waylaid by a site launch.I’ll include your advice when I do.

  4. An update – sometime later!I had mail piping successfully as of my last comment, but PHP was failing when the pipe application was hit. I’d left it for some time, as I had other priorities. Today I decided to sit down and look at the mail server as I had some SMTP problems, and with a friend was going to look at the pipe issue too. As I fired up the laptop, the client pinged me to say mail was down. How ironic. I’d made an error a couple of hours earlier in the /etc/postfix/master.cf trying to get SMTP working. I removed the line, restarted postfix, and lo and behold, the mail queue started working, smtp started working, and the pipe started working.I don’t even pretend to understand… But most importantly this means that the qmail alias method in my comment above works to completion. And it’s a hell of a lot simpler than any of the other methods, which didn’t even work for me.

  5. I am following this same tutorial but adapting it to my setup since I don’t use a control panel (Nginx + Command Line). Do you know what the issue would be for the email message not to show up in Osticket when it is piped?

  6. At a guess the PHP script that processes the piped mail might be having issues – I had the same problem at one point. I would suggest checking your error logs and searchng for pipe.php

  7. For those who are getting the permission denied error, replace apache:apache with the user and group that your php file is "owned" by :DWorked for me 😀

  8. I was able to get piping working for OSTicket with postfix on plesk 10.3 (centos5 OS). I started receiving the permission denied error message (as described at the end of step5). However I changed the username and group from apache:apache to the actual user and group of the file (ftp user in my case) within the line entered into master.cf (step 4) and this resolved the permission denied error.

  9. Yes, thanks to Ross and Broliv for both pinting that out within a day of each other! For PHP to be able to execute the script at the end of your pipe (as it were), that script will need the same user and group as any normal php file on that domain. Easiest way to find out is check what other PHP files on your domain are running as (#ls -l on your httpdocs folder will show you) and then|:# chown {owner} {script}.phpand# chgrp {group} {script}.phpOn Plesk the user will be the ftp user you set up for the domain, and group will normally be psacln.

  10. I think I should clarify that – I’m using a technique I found on this link that utilises mail aliases:
    http://www.thevisionworld.com/vision-helpdesk-faqs-exim-postfix-qmail-sendmail-email-piping.html
    The location on my Plesk is
    /var/qmail/mailnames/{domain.tld}/{address}/.qmail
    And I simply include the pipe command on a single line thus:
    |/var/www/vhosts/thealternativecommunity.com/subdomains/support/httpdocs/api/pipe.php
    With this method you can also have aliases to forward incoming mail to your support team, by including them on seperate lines:
    &address@domain.tld
    So my complete qmail file looks like this:
    | true
    |/var/www/vhosts/{domain.tld}.com/subdomains/support/httpdocs/api/pipe.php
    | /usr/bin/deliverquota ./Maildir&address@domain.tld

    (Note I am running osTicket on a support.domain.tld subdomain)
    To set permission, EVERY folder in the path to pipe,php must be chmod o+x
    I also had to chmod o+x api.inc.php

  11. Sorry, i don´t understand, i have an important error postfix/qmgr
    socket: malformed response

    /var/www/vhosts/mydomain.com/httpdocs/helpdesk/api/pipe.php

    it`s osticket support file, but i don´t undertand the problem.

    1. Hi Sergio – I’m afraid I can’t really help with that. I only have experience of setting it up, not troubleshooting.

      You two best bets are:
      1) Google for “postfix/qmgr socket: malformed response”
      2) Try the osTicket forums or support channels

Leave a Reply

Your email address will not be published. Required fields are marked *