Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Rewrite Mail sending address on the fly Apps
A slightly long-winded hint, but one that I think lots of you out there will find quite useful. Firstly though, why am I interested in changing how my email address looks depending on where it gets sent to? Am I an aspiring spammer, plotting to convince you that your Mac will be plagued by viruses unless you buy lots of v1agra from me?

Not at all! The reason is this: I have a domain. They are fairly cheap to buy and have a feature such that any_email@yourdomain.address will be caught and forwarded to the same 'catch-all' address. Whenever I contact a company, I like to say that my address is, particularly if they are not a reputable company. That way, if they sell my email address to a spammer (or whatever), it is only their specific address that is compromised, and that can easily be configured to reject all mail via your domain host. I also find it useful for advanced searching: all of my eBay correspondence (i.e. eBay, PayPal, and whoever I buy/sell from) use the same address on my domain, so I can quickly check out my eBay activity despite that fact that these people may have nothing else in common.

But now onto the crux of the hint ... if I use Mail to send an email to DodgyCompany Inc, how do I make it look like the message is indeed from I could go into Mail's account preferences and change the From text. Or I could have a different account set up for each company that I send to. But both of these ideas are quite tiresome for anything other than a one-off. Besides, this kind of mail manipulation is bread and butter stuff to Unix, and guess what lurks under the hood of our friendly Macs?

Now, we are briefly going to dabble in the nasty Unix world, but not for long; hence why I didn't mark this hint in the Unix category. We will be using postfix to send email (there are already plenty of fine hints, not to mention the Postfix Enabler, to get you going with this, so I won't go into the details here). Then we are going to use a tool called procmail (already installed on your Mac) to alter the emails.

Start by opening Finder and then press Shift-Command-G to get the Go to Folder dialog, and type in /etc/postfix, then press Return. Create a copy of somewhere safe! Now click on and press Command-I (Get Info). In the Info window, expand the Ownership & Permissions section, and then the Details to view the owner of the file. Change the owner to be yourself (you will need to provide an administrator password to do this). Now click on a blank part of the folder and do the same again (i.e. press Command-I and change the owner to be yourself) and then open in TextEdit.

This file looks nasty but don't worry! We need to change two small parts. First look (about halfway down the file) for a line like this:
smtp      inet  n       -       n       -       -       smtpd
Now add the following directly beneath:
        -o content_filter=filter:dummy
When done, the two lines should look like this:
smtp      inet  n       -       n       -       -       smtpd
        -o content_filter=filter:dummy
One more change to go! Add the following to the bottom of the file (replace joebloggs with your actual user name):
filter    unix  -       n       n       -       10      pipe
    flags=Rq user=joebloggs argv=/usr/bin/procmail /Users/joebloggs/.mailrecipe
Now save, open up the info windows on both the file and its folder, and change the owner back to system.

But what have we achieved by doing the above? We have told postfix that whenever it receives mail via smtp (e.g. from Mail), to send the mail for extra processing to procmail. Now, those crazy procmail developers call each procmail rule a 'recipe.' These recipes can be a little tricky to write, and because I promised that this wasn't really a Unix hint, I've written a basic utility called Recipe Manager to generate the recipes for you! (Instructions for its use are on the linked site.)

If you're still reading this hint, then give yourself a pat on the back! You now have (if you've downloaded the application and run it) a Postfix/procmail system set up on your Mac! If Postfix isn't running and you haven't yet looked at the other Postfix hints, type sudo Postfix start into a Terminal window (you may need to do this as an administrator user) to start it up.

All that remains is to point Mail at your shiny new Postfix server. To do this, go to the Accounts section of Mail's Preferences, select the Outgoing Mail Server (SMTP) list, click on Add server..., and enter localhost in the Outgoing Mail Server box. Click OK. Now, whenever you select 'localhost' as the SMTP server, you will be using the address rewriting facility from this hint. Select your old server to return to normality.

[robg adds: I haven't tested this one...]
  • Currently 2.75 / 5
  You rated: 3 / 5 (4 votes cast)

Rewrite Mail sending address on the fly | 14 comments | Create New Account
Click here to return to the 'Rewrite Mail sending address on the fly' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Rewrite Mail sending address on the fly
Authored by: on Aug 23, '06 09:03:42AM

Or you can list your email addresses separated by comma in your account information "E-Mail address" field. Then you can easily choose your "From" address from the dropdown box. There's even more. When you reply to email sent to some specific address, will choose the right "From" address for you automatically.

[ Reply to This | # ]
Rewrite Mail sending address on the fly
Authored by: mfichtner on Aug 23, '06 09:16:37AM

Thanks a lot,! I've been looking for something like this for a while now and had no idea it could be accomplished so easily. :) Has this already been published as a hint on its own? It would certainly be worth it.

[ Reply to This | # ]
Rewrite Mail sending address on the fly
Authored by: zane on Aug 23, '06 07:23:54PM

Yeh totally! I wish this sub-hint was the main hint so I could rate it up - it's worth at least a shuffle in my book ;)

I had no idea I could put comma separated addresses within the one account. Now I can remove the 20 million superfluous accounts I've set up in mail just for this purpose.

Nice one dude. :)

[ Reply to This | # ]
Rewrite Mail sending address on the fly
Authored by: sophistry on Aug 23, '06 09:25:31AM

Putting comma separated addresses in the from field of doesn't change the Full Name field so all your full names for the comma separated email from addresses have the same Full name. If you don't like this, just delete Full Name.


[ Reply to This | # ]
Rewrite Mail sending address on the fly
Authored by: Oceanhints1 on Aug 23, '06 10:52:01AM

As posted by others, putting commas between addresses in your account details means you don't have to go to trouble of this long drawn out postfix hint.

Respect to the poster for finding this alternative way of sending from alternate addresses but as usual Apple already have built in the functionality!

[ Reply to This | # ]
Rewrite Mail sending address on the fly
Authored by: cougar718 on Aug 23, '06 09:04:31PM


I have multiple email accounts from Comcast, but have different usernames, so this hint would not apply to me right? This hint is only for emails like

Rick alias cougar

[ Reply to This | # ]
Insanely painful solution
Authored by: SOX on Aug 23, '06 11:13:44AM

Uh how about doing this the easy way?

just put a prefix on the name.
instead of dodgyCompany,
call it

then just add the rule:
"TO" begins_with "XXX"

to file them.

[ Reply to This | # ]
Rewrite Mail sending address on the fly
Authored by: JadeNB on Aug 23, '06 12:52:25PM

For those of us who don't own a domain, there are other solutions, such as Spamgourmet, out there. Aside from getting an upset call from a small company who wanted to know why I had their company's name in my e-mail address, this service works well for me -- and it lets you send mail from your Spamgourmet address(es).

[ Reply to This | # ]
A much simpler solution via Applescript
Authored by: leono on Aug 23, '06 01:17:04PM
The following AppleScript will allow you to create a message with an ad-hoc email address:

tell application "Mail"
	display dialog "What From address do you desire?" default answer ""
	set newSender to text returned of the result
	set newMessage to make new outgoing message
	tell newMessage
		set visible to true
		set sender to newSender
		make new bcc recipient with properties {address:newSender, name:newSender}
	end tell
end tell

It simply creates asks what email you want to send from and creates a new message with that From address. I've got it set up to BCC me since these messages don't get automatically stored in your Sent folder by Mail.

Since Tiger's (IIRC) Mail program lost it's nice Scripts menu, I put this in my Mail Scripts folder (~/Library/Scripts/Applications/Mail) and use FastScripts to assign it a hotkey.

This and my other Applescripts can be found at, but be warned that that page is out of date, so ignore the instructions there, and know that the Reply versions of these scripts don't work in Tiger since Apple broke something.

[ Reply to This | # ]
Re: A much simpler solution via Applescript
Authored by: sjk on Aug 24, '06 10:21:03AM

Your script (or a variant of it) will sure be more convenient than editing infrequently used sender addresses in the single-line Email Addresses field. Thanks!

[ Reply to This | # ]
Easier (better) way with Postfix
Authored by: sr105 on Aug 24, '06 08:01:41AM

Instead of setting your From: to, use and set recipient_delimiter to '-' in your postfix file. When a new mail arrives addressed like that, Postfix tries to see if the user 'username-company' exists and if not, it falls back to the first (previous?) delimiter, '-', and tries just 'username'.

This is a better way of addressing, because it allows multiple users to use the functionality and avoids having to mess with the aliases file or unknown_user setting. The reason I use '-' for a delimiter instead of the default '+' is that a lot of websites don't allow '+' in e-mail address fields, but '-' always works.

[ Reply to This | # ]
Authored by: mistersquid on Aug 24, '06 08:16:25AM

Do not use this hint if you have a full production mail server that is using postfix and procmail already. Any SMTP handoffs to procmail will be incorrectly delivered to the user specified in the hint but will be so malformed that checking using a POP client (haven't checked IMAP) will not indicate failure.

I found this out the hard way after trying a version of this hint on a production server with procmail hooks to SpamAssassin.

Using procmail to rewrite outgoing mail seems just wrong.

[ Reply to This | # ]
Authored by: dfbills on Aug 24, '06 04:32:28PM

You will also score fairly high in spam assassin.


[ Reply to This | # ]
Rewrite Mail sending address on the fly
Authored by: sd on Aug 28, '06 07:31:12AM
Instead of using, would be more standard. For those interested in, this page give good information about 'address extension'...
Even without this hint that requires you have your own domain, it is a good idea to use this way to fill in web forms:

[ Reply to This | # ]