The FreeBSD Diary |
(TM) | Providing practical examples since 1998If you buy from Amazon USA, please support us by using this link. |
Using foo+bar@ email addresses with Postfix and procmail
11 April 2003
|
Mail addresses can be expressed as
Address extensions have been around for some time. They are a conceptual entity and are
not actually defined in any RFC.
Convention dictates what an address extension is and how it is used. Let us use
For reference, the following may be useful: |
Yeah, well, why bother?
|
Why am I doing this? Why bother with address extensions? The answer is simple: because it makes life easier. In this particular case, I am setting up a new development box for FreshPorts and FreshSource. This box is much faster than the existing environment. It will contain a development, a test, and a beta environment. I will want cvs-all messages going to each of those databases. I do this by sending the messages to dan+dev, dan+test, and dan+beta respectively[1]. I use procmail to process the incoming mail. This is very useful as it allows me to process the mail into the appropriate FreshPorts database. Without this ability, I would resort to different users for each database. Having just one user (me!) makes this all very easy and simple. [1] - no, I don't have three subscriptions to the cvs-all mailing list. I have one. I use local aliases to copy that single message to three local addresses. |
What's in it for me?
|
You might be asking that question now. Let me give you an example. Let's guess that you are subscribed to three different mailing lists. It's nice to keep all the messages for a particular list in a separate folder. There are many different ways to do this. I will not list them. Let's assume all the mailing lists have nothing in common and therefore you need three different entries such as these:
Worse still, there is nothing in the mailing list email messages which is easy to identify. Rather
than check To:, From:, and possible CC:, you can avoid all this by adding your very own key; your
subscription address. Let's assume I subscribe to the above lists using the following email addresses:
where ARG is the address extension.
But how do you get that extension? Postfix to the rescue! |
Address extensions with Postfix
|
The Postfix MTA supplies many environment variables when local delivery is being performed. man 8 local contains the information you need. Specifically, this extract from the EXTERNAL COMMAND DELIVERY section:
This variable is available to you within your ~/.forward script, which is the
normal method for invoking procmail. Here is what I'm using:
Read
See also the man page section titled ADDRESS EXTENSION where it documents that
|
The new procmail recipe
|
Here is how to use the address extension (as supplied by Postfix) within procmail. I found this gem in the procmail tips.
The address extension is passed in as $1 by the .forward
script. You can add more parameters to .forward as needed. The first is always
$1 , the second will be $2 , etc. You cannot access this
variable directly and you must assign it to a variable.
|
Passing the extension along
|
Sometimes you need to forward an email and include the extension you were given. This recipe does that:
|
Other references
|
I found Procmail Quick Reference Guide useful when devising my recipes. |
The last word
|
My thanks to those on the procmail and Postfix mailing lists for pointing me in the right direction. |