Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Postfix To: address rewrite based on envelope_recipient

Posted on 2014-03-24
3
Medium Priority
?
1,287 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
We aren’t perfect, just like everyone else.  Check out the email errors our community caught and learn the top errors every email marketer should avoid.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
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…

722 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