Rewrite Address Based on _Recipient_

This is a discussion on Rewrite Address Based on _Recipient_ within the mailing.postfix.users forums, part of the Mail Servers and Related category; Hi. I want to know if there is a way to rewrite the sender address based on the recipient of ...


Go Back   Usenet Forums > Mail Servers and Related > mailing.postfix.users

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-10-2006
s.fenster@gmail.com
 
Posts: n/a
Default Rewrite Address Based on _Recipient_

Hi. I want to know if there is a way to rewrite the sender address
based on the recipient of the address.

So for example, if the email is addressed to a@domain.com, re-write the
from address to x@domain.com. Otherwise, keep the sender address as it
is.

I was looking at sender_canonical and regular expressions, but it looks
like it applies the regular expression matching pattern to the sender
address and rewrites the sender address. I want to apply the regular
expression to the recipient but rewrite the sender address.

I ultimately want to use the virtual table to redirect email for
a@domain.com to some other email address, but instead of retaining the
original sender address, I want to change the sender address.

Any ideas on how to do this?

Thanks,
Seth

Reply With Quote
  #2 (permalink)  
Old 03-10-2006
Greg Hackney
 
Posts: n/a
Default Re: Rewrite Address Based on _Recipient_


I don't think this can be done using just Postfix alone.

Postfix can do canonical mapping of sender addresses, and of recipient addresses,
but not do one depending on the value of another.

--
Greg



s.fenster@gmail.com wrote:
> Hi. I want to know if there is a way to rewrite the sender address
> based on the recipient of the address.
>
> So for example, if the email is addressed to a@domain.com, re-write the
> from address to x@domain.com. Otherwise, keep the sender address as it
> is.
>
> I was looking at sender_canonical and regular expressions, but it looks
> like it applies the regular expression matching pattern to the sender
> address and rewrites the sender address. I want to apply the regular
> expression to the recipient but rewrite the sender address.
>
> I ultimately want to use the virtual table to redirect email for
> a@domain.com to some other email address, but instead of retaining the
> original sender address, I want to change the sender address.
>
> Any ideas on how to do this?
>
> Thanks,
> Seth
>

Reply With Quote
  #3 (permalink)  
Old 03-11-2006
s.fenster@gmail.com
 
Posts: n/a
Default Re: Rewrite Address Based on _Recipient_

Thanks Greg.

Do you have any recommendations on how I can do this with other
programs? Would procmail do this?

Right now I have Outlook forwarding the emails based on a rule
template, but this is cheesy, since I have to have a computer logged in
all of the time.

Thanks,

Seth

Reply With Quote
  #4 (permalink)  
Old 03-11-2006
Greg Hackney
 
Posts: n/a
Default Re: Rewrite Address Based on _Recipient_


You could do it easily with procmail and formail.

In the example below (assuming that I understand what you want to do):

recipient@domain.com is the original recipient address
sender@domain.com is the new forced sender address you want to use
newaccount@domain.com is the new recipient address you want the email forwared to



--< ~recipient/.forward >--
|"exec /usr/bin/procmail"

--< ~recipient/.procmailrc >--
:0fw
| /usr/bin/formail -i "From: SENDER_NAME <sender@domain.com>" | /usr/lib/sendmail -f sender@domain.com newaccount@domain.com


--
Greg




s.fenster@gmail.com wrote:
> Thanks Greg.
>
> Do you have any recommendations on how I can do this with other
> programs? Would procmail do this?


Reply With Quote
  #5 (permalink)  
Old 03-11-2006
s.fenster@gmail.com
 
Posts: n/a
Default Re: Rewrite Address Based on _Recipient_

That looks like greek to me; I don't know anything about procmail. But
I will study up on it. From your suggestion, it looks like procmail is
the way to go. Thanks!

Reply With Quote
  #6 (permalink)  
Old 03-12-2006
s.fenster@gmail.com
 
Posts: n/a
Default Re: Rewrite Address Based on _Recipient_

Greg,

I used your recipe and it worked beautifully. I had to tweak it. For
some reason, the fax service wasn't recognizing the recipient address.
I was sending it to myfaxnumber@faxservice.com. The emailed response
was "no valid fax number found in message". I tried using
faxnumber@faxservice.com, faxnumber@faxservice.com
<faxnumber@faxservice.com>, and just <faxnumber@faxservice.com>. None
of them worked. I don't know what format it was expecting, or what
format the recipient parameter in sendmail expects.

I did get it to work by using the -A option in formail to append the
"To" address and the -t option in sendmail to extract the "To" address.

Thanks for your help!

Seth

Reply With Quote
  #7 (permalink)  
Old 03-12-2006
Greg Hackney
 
Posts: n/a
Default Re: Rewrite Address Based on _Recipient_

s.fenster@gmail.com wrote:

> For some reason, the fax service wasn't recognizing the recipient address.
> I did get it to work by using the -A option in formail to append the
> "To" address and the -t option in sendmail to extract the "To" address.


I can explain why it wasn't working. But it's long winded:

There are two different types of addresses. There are envelope addresses, and there
are header addresses. You can think of these along the lines of a postal letter:

On the outside of the postal letter, it shows where the email is to be delivered to,
and the sender's address. These equate to the envelope addresses used in the SMTP
protocol. Postfix uses these to deliver or return the mail, just as a postman would do
for a letter. The end users usually never see the email envelope addresses. They are just used
in the SMTP delivery protocol.

On the inside of a postal envelope, there's a letter. This equates to the body of the
email message. Written on the letter, it might begin with "Dear Mom" and end with "Love Seth".
These are equivalent to the To: and From: headers in an email. Just as the postman never uses
what's contained on the letter for mail routing, Postfix never uses the To: and From: headers for
mail routing.

The 'formail" program modifies the content of the mail message body headers, such as the To: and From: lines.

Using my original example, we only modified the From: field, and not the To: field. So, the To: field
still contained "recipient@domain.com" rather than "faxnumber@domain.com". The pipe through the "sendmail -f"
program delivered it to faxnumber@domain.com because that's what the envelope address contained.

Apparently that FAX progam examines the message body headers to determine where to send the FAX, in particular
the To: header. So that's why it worked when you changed formail to modify the To: field in addition to the From: field.

I'm glad that this particular situation works for you. But be aware that in using the "-A" option to formail, the
message will have 2 To: lines. Normally you'd want the "-i" or "-I" options instead of "-A".

--
Greg











Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:43 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0