Solved

Postfix To: address rewrite based on envelope_recipient

Posted on 2014-03-24
3
1,157 Views
Last Modified: 2014-03-30
I'm trying to setup e-mail aliasing for a helpdesk software (Absolute Service).  The theory is that each sender OU translates into a different alias which is then sent to a common account so that the helpdesk software can retrieve the message and assign it to the correct team based on the aliase it was sent to.   For each OU in my google apps domain I am rewriting the envelope_recipient to route the message to an alias which identifies the senders OU.  

For example.  A sender in OU1 will write a message to helpdesk@domain.com, when google rewrites the envelope_recipient the message will be turned into OU1-helpdesk@domain.com.  The issue is that the "To: Helpdesk <helpdesk@domain.com>" doesn't change on the message and this is the part that the helpdesk software is looking at to determine the appropriate team to assign the automatically created ticket.

My thoughts were to go one step further and rewrite the envelope_recipient to be OU1-helpdesk@localserver.domain.com and then have postfix rewrite the "To:" field but this has proved more difficult than I anticipated since postfix will only search and replace in the same header line.

I need postfix or something else to rewrite "To: Helpdesk <heldpesk@primary.com>" in a message to be something else such as "To: Helpdesk <OU1-helpdesk@primary.com>" based on the envelope_recipient which would be OU1-helpdesk@primary.com.
0
Comment
Question by:CoryInIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 62

Expert Comment

by:gheist
ID: 39951591
Modifyind message content is bad. There is no limit in body to: fields, What do you do with message with 30 cc: fields 30 reply-to and 30 to: fields but 3 envelope recipients?
0
 
LVL 1

Accepted Solution

by:
CoryInIT earned 0 total points
ID: 39953497
It appears this isn't possible in postfix alone since it will only process headers a line at a time which won't allow you to do a logical if statement from one line then process another.  Instead here is what we did.

We had each Google Apps OU add a custom header to each message destined for our helpdesk@domain.com address.  It looked like this:
X-COMPANY-To: OU-helpdesk@domain.com
It also re-routed the e-mail from helpdesk@domain.com to helpdesk@localserver.domain.com which was a local Max OSX server running procmail.

We then used the following configs on OSX mail server to process the incoming email.  Making an /etc/aliases entry to change heldpesk@localserver.domain.com to the local account ashelpdesk.

In the ashelpdesk user home folder I added the following files:
.forward file contents:
|/usr/bin/procmail

.procmailrc file contents:
MAILDIR=/var/spool/imap/dovecot/mail/SOMEUID/new
LOGFILE=$HOME/procmail.log
SHELL=/bin/sh

FROM_=`formail -rt -xTo: | expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`
TO_=`formail -xX-COMPANY-To: | expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`
:0c
* ^X-COMPANY-To:
{
  :0fhw
  | formail -i "From: ${FROM_}" -I "To: ${TO_}"
  :0
  !${TO_}
}

The procmail extracts the original From and the custom header To fields from the message and then as long as the custom field exists in the message it rewrites the header_from and header_to fields in the message and forwards it to the custom header to address.
0
 
LVL 1

Author Closing Comment

by:CoryInIT
ID: 39964693
The result is a email which goes to the helpdesk@domain.com account with the appropriate aliase in the To: field of OU-helpdesk@domain.com.  This way our helpdesk software will assign the ticket created from this e-mail to the correct service team.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Resolve DNS query failed errors for Exchange
Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
This Micro Tutorial will demonstrate the easy use of Gmail embedding images in your email so the recipient of your email can view them in context.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question