tags:

views:

3274

answers:

5

Sending a message from the Unix command line using mail TO_ADDR results in an email from $USER@$HOSTNAME. Is there a way to change the "From:" address inserted by mail?

For the record, I'm using GNU Mailutils 1.1/1.2 on Ubuntu (but I've seen the same behavior with Fedora and RHEL).

[EDIT]

$ mail -s Testing [email protected]                                                                  
Cc: 
From: [email protected]

Testing
.

yields

Subject: Testing
To: <[email protected]>
X-Mailer: mail (GNU Mailutils 1.1)
Message-Id: <E1KdTJj-00025z-RK@localhost>
From: <chris@localhost>
Date: Wed, 10 Sep 2008 13:17:23 -0400

From: [email protected]

Testing

The "From: [email protected]" line is part of the message body, not part of the header.

+2  A: 

Here are some options:

  • If you have privelige enough, configure sendmail to do rewrites with the generics table

  • Write the entire header yourself (or mail it to yourself, save the entire message with all headers, and re-edit, and send it with rmail from the command line

  • Send directly with sendmail, use the "-f" command line flag and don't include your "From:" line in your message

These aren't all exactly the same, but I'll leave it to you look into it further.

On my portable, I have sendmail authenticating as a client to an outgoing mail server and I use generics to make returning mail come to another account. It works like a charm. I aggregate incoming mail with fetchmail.

Thomas Kammeyer
+1  A: 

In my version of mail ( Debian linux 4.0 ) the following options work for controlling the source / reply addresses

  • the -a switch, for additional headers to apply, supplying a From: header on the command line that will be appended to the outgoing mail header
  • the $REPLYTO environment variable specifies a Reply-To: header

so the following sequence

export [email protected]
mail -aFrom:[email protected] -s 'Testing'

The result, in my mail clients, is a mail from [email protected], which any replies to will default to [email protected]

cms
-a works like a charm! But REPLYTO isn't working at all...
Chris Conway
I just tested it again here to make sure, and it works fine for me. Not all mail clients work well with Reply-To, but I'd have thought that was a solved problem by now.The REPLYTO env variable is mentioned in the man page, Other UNIX mailers honour it, emacs etc. Still, I guess you have a fix.
cms
I don't think it's the mail client... I don't see the Reply-To header in the raw message text. But, yeah, -a is sufficient.
Chris Conway
Odd. does 'man mail' suggest that it ought to work ?
cms
No, it doesn't. But: "The complete GNU mailutils manual is not available in Debian systems due to licensing reasons." -aReply-To:... works.
Chris Conway
I also don't see any mention of REPLYTO at http://www.gnu.org/software/mailutils/manual/mailutils.html
Chris Conway
Thank you for replying. My /usr/bin/mail comes from the mailx package, which I think is derived from BSD-mail. And most of my unix machines are BSD.
cms
A: 

for me -a is not working ..any other alternative...pls let me know

A: 

this worked for me

echo "hi root"|mail [email protected] -s'testinggg' root

+1  A: 

On Centos 5.3 I'm able to do:

mail -s "Subject" [email protected] -- -f [email protected] < body

The double dash stops mail from parsing the -f argument and passes it along to sendmail itself.

Beau