[TriLUG] Command line mail
Jeremy Portzer
jeremyp at pobox.com
Mon Jun 9 16:21:31 EDT 2003
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!
--
/=====================================================================\
| Jeremy Portzer jeremyp at pobox.com trilug.org/~jeremy |
| GPG Fingerprint: 712D 77C7 AB2D 2130 989F E135 6F9F F7BC CC1A 7B92 |
\=====================================================================/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://www.trilug.org/pipermail/trilug/attachments/20030609/d45dd449/attachment.pgp>
More information about the TriLUG
mailing list