[comp.unix.questions] 'Cannot mail directly to files' from sendmail

bob@acornrc.UUCP (Bob Weissman) (12/11/87)

All the documentation I can find says that you can mail to a file instead
of a user's mailbox by using a recipient which {begins with, contains} a
'/' character.  (Docs differ on whether the recipient name has to begin
with the '/', but this is immaterial here.)

I know I can do this with /usr/ucb/mail <filename>.  Fine.  I want to do
it (in a script) with /usr/lib/sendmail <filename>, but sendmail gives the
error message 'Cannot mail directly to files'.  The script is running as
UUCP, driven by a "|script" entry in the aliases file.

Looking at the code in recipient.c, it appears that sendmail is rather
arbitrarily deciding it doesn't want to do what I want.  (I am not
claiming here that I understand all this code!)

Any ideas (1) why sendmail is refusing me and (2) how to get around this?

This is a Vax running 4.2bsd.

Thanks,
-- 
Bob Weissman
Internet:	bob@acornrc.UUCP
UUCP:		...!{ ames | decwrl | oliveb | apple }!acornrc!bob
Arpanet:	bob%acornrc.UUCP@AMES.ARPA

pdb@sei.cmu.edu (Patrick Barron) (12/11/87)

In article <538@acornrc.UUCP> bob@acornrc.UUCP (Bob Weissman) writes:
>I know I can do this with /usr/ucb/mail <filename>.  Fine.  I want to do
>it (in a script) with /usr/lib/sendmail <filename>, but sendmail gives the
>error message 'Cannot mail directly to files'.  The script is running as
>UUCP, driven by a "|script" entry in the aliases file.
>
>Looking at the code in recipient.c, it appears that sendmail is rather
>arbitrarily deciding it doesn't want to do what I want.  (I am not
>claiming here that I understand all this code!)
>
>Any ideas (1) why sendmail is refusing me and (2) how to get around this?

Sendmail will only mail to files if the filename appears in an alias
expansion, or in someone's ".forward" file; this is for security reasons.
Suppose your sendmail runs setuid to root, and someone trys to mail
something to any arbitrary file, oh, say, "/etc/init" for instance.  I
think you can see that it would be a disaster.  Mail to pipes (through
the "prog" mailer is similarly restricted.

To get mail to a file, you need an entry in /usr/lib/aliases for that
file.  For example, if you wanted to mail stuff to /usr/foo/bar, you'd
need an alias entry like:

  foo:    /usr/foo/bar

and you'd mail it to "foo" instead.

Individual users can cause their mail to be appended to a file (or sent
through a filter) by putting an appropriate entry in their ".forward"
file, so they wouldn't need to mess around with the aliases file.

--Pat.