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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 > |
|
|||
|
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 |
|
|||
|
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? |
|
|||
|
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 |
|
|||
|
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 |