Solved

Postfix To: address rewrite based on envelope_recipient

Posted on 2014-03-24
3
1,102 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
  • 2
3 Comments
 
LVL 61

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

930 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now