[TriLUG] Command line mail

Jon Carnes jonc at nc.rr.com
Mon Jun 9 21:48:58 EDT 2003


I like Jeremy's answer.  You should be able to replace the actual "mail"
function with a script with just a bit of playing.

However, if you don't like that idea, here is an alternative:
 - download the source RPM for Mailx
 - rpm -i the_source_rpm
 - cd /usr/src/RPMS/SOURCES/
 - tar -xzf mailx-...tar.gz
 - cd mailx-...
 - grep From *

All that took me about 5 minutes.  You can see fairly clearly where you
should edit the code.  If you like, simply hard code the From statements
so that they are from the user you want.  Then reassemble the tarfile
and re-create the rpm, copy the current /bin/mail binary somewhere safe
and install the new rpm. Name the new /bin/mail something notable like:
mail_from_opennms and put your old one back.

Any mail sent using this binary will always show the mail as coming
From: opennms at myserver.mydomain

It's an easy solution and shouldn't cost you more than an hour of your
time... and you'll learn why the call it "Open Source".

Jon Carnes

Note: I grep'ed the patch files from the expanded source RPM and didn't
see anything that affected hard-coding a name inside the From headers.

On Mon, 2003-06-09 at 16:21, Jeremy Portzer wrote:
> On Mon, 2003-06-09 at 15:50, Tarus Balog wrote:
> > Gang:
> > 
> > OpenNMS uses /bin/mail to send mail notifications. Since the actiond 
> > process runs as root, the mail appears sent from 
> > "root at myserver.mydomain".
> > 
> > They would like it to be something like "opennms at myserver.mydomain". So 
> > I have two questions:
> > 
> > 1) I don't think this is possible with /bin/mail. I am right?
> 
> It doesn't appear to have the option to change the From: line, no.
> 
> > 2) Is there another command line mail program that *would* allow one to 
> > set the "From" field? It would need to function similarly to /bin/mail 
> > to be a drop in replacement.
> 
> It wouldn't exactly be a drop-in replacement, but it would be pretty
> simple to use "sendmail -t" to send your mail.   When sendmail is
> invoked with the -t flag, it will read the 'to' and 'from' from the
> headers you give it on standard input.  For example:
> 
> bash$ /usr/sbin/sendmail -t
> To:  Tarus Balog <tarus at sortova.com>
> From: Jeremy Portzer <jeremyp at pobox.com>
> Date: Mon, 9 Jun 2003 15:50:27 -0400
> Subject: this is an email
> 
> This is the body.
> 
> <end of standard input; you would type ^D>
> bash$
> 
> As you can see, this method is pretty easily scriptable.  What language
> are you using?  There are various Perl or Python modules for sending
> mail also that might be more straightfoward.  The hardest part in
> generating the above information is formatting the date, but you could
> always just call /usr/bin/date with the appropriate formatting codes.
> 
> --Jeremy, who has been programming with perl's Mail::Sender module all
> day today and is just about tired of email!




More information about the TriLUG mailing list