Solved

Postfix To: address rewrite based on envelope_recipient

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Explore the encryption capabilities built into Google Apps and how these features can help you meet privacy policy and regulatory compliance, but are not a full solution. Understand and compare the most popular email encryption services for Google A…
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.
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
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.

743 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

20 Experts available now in Live!

Get 1:1 Help Now