Re: Configuring FreeBSD 6.2 to use sendmail for sending only



On Thu, 30 Aug 2007 18:14:55 -0700 (PDT) L Goodwin <xrayv19@xxxxxxxxx> wrote:

--- Derek Ragona <derek@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:

[ slashing mercilessly ]

--- Chuck Swiger <cswiger@xxxxxxx> wrote:
[..]
Although, it is entirely reasonable to consider
using Postfix instead.

Here is a sample script that you can use as a
template:
=======================================================
#!/bin/sh

#define any commands you will use
MAILFILE=mymailfile
MAILFILE2=mymailfile2
SENDTO=derek@xxxxxxxxxxxxxxxxxxxxxxxx
CCTO=derek@xxxxxxxxxxxxxxxxxxxxxxxx
MAIL=/usr/bin/mail
AWK=/usr/bin/awk
CAT=/bin/cat
TR=/usr/bin/tr
TEMPDIR=/tmp

#make sure we have paths
export PATH=$PATH:/usr/local/sbin:/usr/local/bin

cd $TEMPDIR
$CAT /etc/passwd | $AWK -F : '{ print $5 }' >
$MAILFILE
$TR -cd "\012-\172" < $MAILFILE > $MAILFILE2
$MAIL -s "My list of real user names subject"
$SENDTO -c $CCTO < $MAILFILE2
=======================================================

Derek, your example brings up another question.

Should I be calling "mail" or "sendmail", and which
mail or sendmail should I invoke if there is more than
one of either? Chuck's example calls sendmail in a
path that does not exist on my system (my sendmail is
in /usr/sbin/). I usually invoke whichever one is
first in my path.

Use whatever works for you, and it never hurts to be specific :)

One more question. Is it ok to run the script (and
send the email) as user root, or should I create a
user account with more limited permissions -- if so,
what limits should I set?

There are so many ways of doing this .. here's another that we'd use to
mail out accounts to members monthly, from text files generated by some
php and mysql magic on another box, by another guy.

Note that this is enforced to be run by user 'subs' (here uid 996), so
that's who these messages are 'From:'. A script run from cron need not
be so paranoid about checking things .. this was hand-run 'when ready'.

#!/bin/sh
# sendacts 7Jan00 smithi .. mail out SubsBot messages .. cleanup 2Oct02
# each *.act file begins with To:, Cc:, X-mailer: etc lines

maildir="/home/subs/bills/$1" # preexisting dir as parameter eg '2000-01'
mailrun="./command.txt" # perline format: 'sendmail -t < userX.act 2>&1'

if [ "`id -u`" != "996" ]; then
echo "$0 must be run as user subs .. 'su subs' and retry .."
elif [ "$1" = "" ]; then
echo "usage: $0 directory"
elif [ ! -d $maildir ]; then
echo "$maildir does not exist .. mkdir first, unpack zipfile there"
elif [ ! -w $maildir ]; then
echo "$maildir is not writeable .. an older locked one, perhaps?"
else
cd $maildir
if [ ! -f $mailrun ]; then
echo "can't find ${maildir}/${mailrun} .. zipfile not unpacked?"
elif [ -f ./mailout.done ]; then
echo "'rm ${maildir}/mailout.done' if you wanna repeat mailout?"
else
umask 27
echo "$0 sending mail:" ; cat $mailrun
. $mailrun
touch ./mailout.done ; echo "$0 done"
exit 0
fi
fi
exit 1

with ./command.txt containing a line per recipient such as:

sendmail -t < user1.act 2>&1
sendmail -t < user2.act 2>&1
[..]
sendmail -t < userN.act 2>&1

and with the *.act files beginning such as:

To: smithi@xxxxxxxxxxxxx
Subject: August 2006 Account for Ian Smith
Cc: subs@xxxxxxxxxxxxx
Reply-to: subs@xxxxxxxxxxxxx
X-Mailer: subsbot v0.9 beta 8.90 :)

Hello Ian Smith,
[..]

HTH, Ian

_______________________________________________
freebsd-questions@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: Windows Service Help
    ... since a Windows service cannot be started directly within the IDE this is where that batch file I was talking about earlier comes into play. ... if you're running the service under another account make sure you check the box for "Show processes from all users" so you'll be able to see the service when it's running. ... echo %SERVICE_DESC% Installer ... I didn't get too in depth on the installation, but in order for a service to be deployed and registered on the target machine you must have an installer class in there. ...
    (microsoft.public.dotnet.languages.csharp)
  • DocMGR <= 0.54.2 arbitrary remote inclusion
    ... It allows for the storage of any file type, ... DocMGR runs on PHP, the Apache ... //make sure this user can alter the account. ... echo nl2br); ...
    (Bugtraq)
  • Re: Email Authentication
    ... | to activate the account. ... that sets the security code. ... echo implode; ...
    (alt.php)
  • Re: "flush queue mode requires no recipient"
    ... Sendmail is a Mail Transport Agent, ... Look *only* at the pid file. ... echo $"Usage: pidfileofproc " ... trap "" SIGPIPE ...
    (comp.mail.sendmail)
  • Re: Better use of awk/sed?
    ... echo "$(echo "$accounts"\ ... It's much easier for you to just tell us what it does than have us try to figure it out from reading the code and coming up with multiple sample inputs to test it and from those test results synthesize the purpose of the script. ... I THINK what you want is to take your list of input files, change the suffix to a comma and add "and" between the final 2 files plus a terminating word "term". ... echo "$account for $files" ...
    (comp.unix.shell)