I'm storing and forwarding (to google apps) emails using the following procmail recipe:

# set vars

# Avoid email loops
* ! ^X-Loop: ${USERNAME}@domain\.nl
  :0c:   #Preserve a copy of the email
  :0fwh  #Adjust some headers before forwarding
  | formail -A"X-Loop: ${USERNAME}@domain.nl" \
  # Forward the email

This works, but when I set up an 'out of office' message in gmail it returns the email to the forwarding system instead of to the original sender.

This probably has to do with the forwarding system adding or replacing a Return-path line and putting the local username and the servername in there.

My question is thus how can I prevent that from happening?

  • The Return-Path header is added by the LDA on delivery, not by Procmail. If your local Sendmail equivalent allows you to set the envelope sender with -f and you have access to this information (perhaps by extracting the Return-Path header on the system where you run Procmail) that should fix the problem, provided your diagnosis is correct. – tripleee Jul 22 '12 at 19:36


# Forward the email
* ^Return-Path:[  ]*\/[^  ].+
{ env=$MATCH }
! ${env+-f "$env"} ${LOCALPART}@apps.domain.nl

As is customary in Procmail recipes, the whitespace inside the square brackets should consist of a space and a tab (both places where the Return-Path header is being matched. I could not write literal tabs from the mobile device I'm typing on).

  • 1
    thanks, worked like a charm! Not sure what went wrong at first, retried editing it from scratch and now it works. – datadevil Aug 14 '12 at 7:20
  • I have the same problem as datadevil that Return-Path is modified after piping through procmail. I tried your solution @tripleee, but procmail says there's no match. – joshu Mar 30 '13 at 2:14
  • No match could mean either that there is no Return-Path: header, or that you mistyped the regex somehow. – tripleee Mar 30 '13 at 8:18
  • @tripleee hi. there is a Return-Path header. I copy and pasted your code as I wanted to avoid mistyping ;) – joshu Mar 30 '13 at 11:03
  • Check that the whitespace in [ ] and [^ ] is a space and a tab. Copy/pasting from a web page might not work correctly, as indicated already in the original answer. – tripleee Mar 30 '13 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.