Forward an email from command line in Linux

emailpostfixubuntu-10.04

I have email files in my Maildir received with postfix server (Ubuntu). Is there a utility that can forward a selected email file to the specified email address? Something like:

cat emailfile | utility to@address.com

I tried to use mail command but it just sent the entire file contents including all technical header information as a plain text, which does not look nice.

cat emailfile | mail -s subject to@address.com

Update

Sorry for not being specific. What I wanted is to forward an email file from a shell script, without attachments, but removing all the header and metadata and presenting it in human-friendly way. Like in gmail, when you click 'forward' it automatically parses the email nicely, adds "forwarded message" text on the top and then puts the body text message. I know I can parse the email file myself and construct a new email, but I thought there was a utility that could save me couple hours.

Best Answer

There are more possibilities than one.

  1. This utility is called sendmail. cat emailfile | sendmail -f to@address.com. Maybe you have to rewrite the mail before, as this does not "forward" the mail, but instead "send" the mail.
  2. Do this in Postfix itself. You could use the many possibilities already present in Postfix to send a mail to the local user and additionally to others (locally and/or remote). Clue: *_alias_maps
Related Topic