Aliasing message with To: field...

I have an email address with my cellular phone that I need my work address forwarded to. The only problem is, my cellular phone email address doesn't accept any messages unless they are addressed specifically to their address (not forwarded).

Example: Only works if addressed to '' - Doesn't work if is forwarded to '443555....' because it goes to their system looking like

So basically, I need to setup some sort of forwarding that makes messages appear as if they are addressed to one address, when really they are addressed to another. Any ideas?? Can this be done with Sendmail? Relaying? Masquerading?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Other than a custom rule in your, I don't think you could theres any way to change the "To" line. Sendmail futzes with the envelope to get the message delivered, but headers like "To" "Subject", etc are the province of the sending mail client. In general sendmail doesn't care what's in the those headers (or even if they are present).

The easiest way I can think of would be to set up an alias that accepts the message, rewrites the "To:" line and mails it. A small perl script that replaces the "To" line and mails it out can be set up as an alias like:

username:  |/path-to-script/cellmailer

I've used something very similar to resend emailed alerts as email to a paging service on my cell phone.
A minute or so after I hit submit I realized there's a trivial way to handle your case. I needed a perl script because I had to do more serious modification of the message. All you need is to change the "To" line which you ought to be able to do with an alias like:

username:  | (sed -e "s/^To:.*/To: cell-page@where/" | mail -w cell-page@where)

This works on Solaris, you might need to change "mail -w" to whatever your OS would use to send a message from the command line.
I'm marking this as answered per the comments.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

drummondAuthor Commented:
I didn't exactly have any luck with the alias file. I don't think I had the syntax entirely right.

However, my first solution was to take a Perl route as well. I wrote a script that basically did the same thing - re-addressed the email and sent it out again. It almost took down our system twice.

I found that when it re-sent the email to my cell phone, it 1) Also sent a copy to anyone who had been carbon copied on the original messages AND 2) this was very bad if someone typed in a wrong address for a carbon copy.

For example, someone would send to and carbon copy "". Well if "" doesn't exist, it sent the thing 200 times, totally clogging up my ISP's system.

I don't know why it happened, but I decided to look for a solution out here. I was hoping for some sort of built in sendmail command so I knew it couldn't be as destructive as the Perl solution was.

Thanks for the post! If I end up sticking with the Perl, I will award you the points.
Ah, you do need to more than just change the "To:" field. The perl script I use, mentioned in the first comment, does exactly that. It reads the message and trashes all of the header lines except "Subject" and the "To" (which it re-writes. Those two lines and the body are sent via email as a page. Note that sendmail doesn't care one bit what the headers are, and will quite happily deliver an email with none of the "standard" headers.

Just in case you don't know... You can tell where the headers end on a Unix system by reading and processing lines until you see a blank line. The spec requires it to be there.

The easiest way of doing this is to have perl write a temp file containing the new message and then use the system call to ship it out to your mail system. On Solaris I use:

system "mail -w pager\ <$tmpf"

Your "mail" command & args might be different. This happens to make debugging the script a trivial task. Comment out the system call and don't unlink the tempfile when the script exits and you can see exactly what the re-mailed message will look like. When it's right you can test by manually invoking what the system call would have done.

drummondAuthor Commented:
You're exactly right! I didn't think to throw out all the information in the header - that's brilliant. And who knew it could be so easy! Consider the points yours - Well earned!
Thanks for the compliment...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.