( locsemege | 2014. 06. 07., szo – 11:37 )

A sendmail szerintem is pilótavizsgás. Én úgy oldottam meg Fedorán - technikai infót, például IP-címet küldenek magukról az általam karbantartott gépek -, hogy feltettem az msmtp nevű SMTP klienst. A /etc/msmtprc file-ban kikommentelve van egy példa, hogyan kell a szolgáltatódat konfigurálni. Mivel az authentikációhoz a jelszó szerepel a file-ban, figyelj arra, hogy root:root 0640-es jogai legyenek a file-nak, hogy ne tudja minden felhsználó a jelszót nézegetni.

Aztán van a /etc/mail.rc file, ez tartozik a mail illetve mailx parancshoz. Ennek a végéről kommentezd ki a set sendmail kezdetű sort, valamint írj bele egy új sort:

# set sendmail="/usr/bin/msmtp"
set sendmail="/usr/local/bin/mailtext"

A /usr/local/bin/mailtext egy saját scriptem, tudniillik az egyik parancssori paramétert nem kompatibilisen állítja elő a mail. Tehát ez a scriptem így néz ki:

#!/bin/bash

i=0
while [ $# -gt 0 ]; do
    if [ x"$1" = x'-r' ]; then
        param[i]='-f'
    else
        param[i]="$1"
    fi
    shift
    ((i++))
done
exec msmtp "${param[@]}"

Látszik, hogy a '-r' kapcsolót cseréli '-f'-re, majd hívja az msmtp-t. A script jogai root:root 0755. A csere egyébként ezért kell:

Részlet a man mail-ből:

       -r address
              Sets  the From address. Overrides any from variable specified in
              environment or startup files.  Tilde escapes are disabled.   The
              -r  address options are passed to the mail transfer agent unless
              SMTP is used.  This option exists for compatibility only; it  is
              recommended to set the from variable directly instead.

Valamint részlet a man msmtp-ből:

              -f, --from=address
                     Set the envelope-from  address.  It  is  only  used  when
                     auto_from is off.
                     If  no account was chosen yet (with --account or --host),
                     this option will choose the first account  that  has  the
                     given  envelope-from address (set with the from command).
                     If no such account is found, "default" is used.

A levél küldése shell scriptből így történik:

mail -s "$subject" -r "$from" "$address" <<-EOF
Ez itt a szövegtörzs.
EOF

A subject, from, address változók értelemszerűen kitöltve.

tr '[:lower:]' '[:upper:]' <<<locsemege
LOCSEMEGE