Solved

Postfix To: address rewrite based on envelope_recipient

Posted on 2014-03-24
3
1,178 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
This Micro Tutorial demonstrates  how Internet marketers work with competitive analysis data, and a common task in data preparation is creating separate column for domains. You will then extract from a list of URLs.
In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…

752 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