Skip site navigation (1)Skip section navigation (2)
Date:      05 Apr 2003 11:01:44 -0800
From:      Ken McGlothlen <mcglk@artlogix.com>
To:        David Banning <david@skytracker.ca>
Cc:        questions@freebsd.org
Subject:   Re: sending mail with a script question
Message-ID:  <86u1dc93af.fsf@ralf.artlogix.com>
In-Reply-To: <20030404234509.A91877@skytrackercanada.com>
References:  <20030404234509.A91877@skytrackercanada.com>

next in thread | previous in thread | raw e-mail | index | archive | help
David Banning <david@skytracker.ca> writes:

| I am running a php program in a browser which eventually compiles some files
| and emails them to a person of their choosing. The problem is that the system
| identifies the browser user as nobody.
| 
| I send the mail using a line something like;
| 
| cat textfile | mutt -s"Quote/Attachments" -afile1 -afile2 john@doe.com
| 
| but the problem is that the recipient sees the sender address as from
| "nobody@ourhost.com", when I want it seen as "david@ourhost.com".  I have the
| name of the user available in the script but I see no way of running the mail
| script as that person since any browser viewing the system is "nobody".

Well, mutt is moderately inappropriate for this purpose.  On the other hand,
you're also including attachments, which is another problem.

If I recall correctly, PHP has a mail command that you may want to check into.
However, a very simple way of doing it is to use sendmail.  That's what it's
designed for.  Your textfile would have to contain the headers:

        From: david@ourhost.com
        Subject: Quote/Attachments

        [contents of textfile]

or you could use

        cat headers textfile | sendmail john@doe.com

Remember, though, that there MUST BE A BLANK LINE between the headers and the
message.  Just make sure the headers file has a blank line at the end.

The MIME attachments are another deal.  For this, you might want to do

        # portinstall mpack

mpack is a MIME packing program (it can also send mail, but not with a
different From address, so we'll leave that out for now).  You'd use it like
this:

        /usr/local/bin/mpack -o /tmp/textfile.$$ bodytext file1 file2
        /bin/cat headerfile /tmp/textfile.$$ | /usr/sbin/sendmail john@doe.com
        /bin/rm textfile.$$

(Note that I'm using explicit paths as a small increase in security.)

Hope that helps.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86u1dc93af.fsf>