[Fli4l_dev] Problem mit OPT mailsend
Harvey
hw234 at gmx.de
Mo Jan 12 20:54:35 CET 2026
Nelson,
>> Heureka! Etappensieg ;) Den Symlink würde ich über die config.txt von
>> easycron im Startscript erzeugen gelassen. Kann man an
>> EASYCRON_MAIL='yes' ankoppeln (und prüfen, ob opt_sendmail aktiviert ist)...
>
> Das klingt nicht richtig. Weil es würde dann nur der Linux-Standard
> erzeugt werden, wenn auch EASYCRON eingesetzt wird. Ich würde das gleich
> im OPT_SENDMAIL erzeugen lassen. Dann funzt die Mailfunktion quasi "out of
> the box".
> Die Prüfung auf OPT_SENDMAIL sollte indes immer passieren wenn
> EASYCRON_MAIL auf "yes" gesetzt wird. Das geht aber denke ich über die
> Parameterprüfung, oder?
Stimmt, da hast Du Recht. Der Symlink gehört (verpflichtend) zu
OPT_MAILSEND und EASYCRON muss bei setzen von EASYCRON_MAIL auf "yes"
auf OPT_SENDMAIL prüfen. So sollte es sein.
>>> Wegen der Config-Datei ... evtl. kann man die beim build schon festlegen.
>>> Also das msmtp nicht nach msmtprc sucht sondern nach msmtp.conf. Ich
>>> stell mir da eine Änderung in der .configure für msmtp vor. Ich weiss ja
>>> nicht was da im Buildroot drin ist.
Habe jetzt gerade mal ein Testsystem aufgesetzt noch einmal genau
hingeschaut. OPT_MAILSEND erstellt /etc/msmtp.conf auf meinem
Testrouter. Auf meinen Archlinux-Systemen jedoch ist es /etc/msmtprc.
Unsere Scripte sind dann wohl fehlerhaft und sollten /etc/msmtprc
erzeugen. So hast du es ja vorher auch geschrieben.
Könntest Du mal opt/etc/rc.d/rc910.mailsend und
opt/usr/local/bin/mailsend-send.sh durch die angehängten Versionen
austauschen und probieren, ob es dann auf Anhieb funktioniert?
Zu Easycron komme ich dann später.
Gruß
Harvey
-------------- nächster Teil --------------
#!/bin/sh
#------------------------------------------------------------------------------
# /etc/rc.d/rc910.mailsend 4.1.0-g0f90798f6M
#
# Creation: 2015-12-21 cspiess
#----------------------------------------------------------------------------
if [ "$OPT_MAILSEND" = yes ]
then
begin_script MAILSEND "setting up opt_mailsend ..."
grep "^MAILSEND_" /etc/rc.cfg > /var/run/mailsend.conf
chmod 744 /var/run/mailsend.conf
# create spool dir
if [ ! -d "${MAILSEND_SPOOL_DIR}" ]
then
mkdir -p "${MAILSEND_SPOOL_DIR}"
log_info "spool directory ${MAILSEND_SPOOL_DIR} created"
fi
chmod 777 "${MAILSEND_SPOOL_DIR}"
# create logdir
case "${MAILSEND_LOGFILE}" in
""|"syslog")
;;
*)
if [ ! -d "`dirname ${MAILSEND_LOGFILE}`" ]
then
mkdir -p "`dirname ${MAILSEND_LOGFILE}`"
log_info "log directory ${MAILSEND_LOGFILE} created"
fi
;;
esac
# create default conf entries
{
echo "defaults"
echo "protocol smtp"
case "${MAILSEND_LOGFILE}" in
"")
echo "logfile"
echo "syslog off"
;;
syslog)
echo "logfile"
echo "syslog on"
;;
*)
echo "logfile ${MAILSEND_LOGFILE}"
echo "syslog off"
;;
esac
} > /etc/msmtprc
_default=0
for _n in `seq 1 ${MAILSEND_N}`
do
# common
eval _account='${MAILSEND_'$_n'_ACCOUNT}'
eval _auth='${MAILSEND_'$_n'_AUTH}'
eval _crypt='${MAILSEND_'$_n'_CRYPT}'
eval _host='${MAILSEND_'$_n'_SMTP_SERVER}'
eval _port='${MAILSEND_'$_n'_SMTP_PORT}'
eval _user='${MAILSEND_'$_n'_SMTP_USERNAME}'
eval _pass='${MAILSEND_'$_n'_SMTP_PASSWORD}'
eval _crypt='$MAILSEND_'$_n'_CRYPT'
eval _test_scert='$MAILSEND_'$_n'_TEST_SCERT'
eval _scert='$MAILSEND_'$_n'_SCERT'
eval _use_ccert='$MAILSEND_'$_n'_USE_CCERT'
eval _ccert='$MAILSEND_'$_n'_CCERT'
eval _ckert='$MAILSEND_'$_n'_CKEY'
if [ "$_account" = "default" ]
then
_default=$_n
fi
{
echo ""
echo "account $_account"
# smtp server
echo "host $_host"
echo "port $_port"
# authentication
case $_auth in
none|pop)
echo "auth off"
;;
*)
echo "auth $_auth"
echo "user $_user"
echo "password $_pass"
;;
esac
# encryption
case $_crypt in
tls)
echo "tls on"
echo "tls_starttls off"
;;
starttls)
echo "tls off"
echo "tls_starttls on"
;;
*)
echo "tls off"
echo "tls_starttls off"
;;
esac
# server certificate
if [ "$_test_scert" = "yes" ]
then
echo "tls_certcheck on"
echo "tls_trust_file $_scert"
else
echo "tls_certcheck off"
fi
# client certificate/key
if [ "$_use_ccert" = "yes" ]
then
echo "tls_cert_file $_ccert"
echo "tls_key_file $_ckey"
fi
} >> /etc/msmtprc
done
if [ $_default -eq 0 ]
then
{
echo ""
echo "account default :${MAILSEND_1_ACCOUNT}"
} >> /etc/msmtprc
fi
# set conf permission
chmod 600 /etc/msmtprc
# symlink for sendmail compatibility
ln -s /usr/bin/msmtp /usr/bin/sendmail
# crontab entry for mailsend-retry, runs every 15 minutes
#----------------------------------------------------------
add_crontab_entry "*/15 * * * *" "/usr/local/bin/mailsend-retry.sh"
end_script
fi
-------------- nächster Teil --------------
#!/bin/sh
#------------------------------------------------------------------------------
# /usr/local/bin/mailsend 4.1.0-g0f90798f6M
#
# Creation: 2015-12-21 cspiess
#------------------------------------------------------------------------------
# helper functions and config variables
. /usr/local/bin/mailsend-helper.sh
# globale variablen
_ACCOUNT='default'
_MAIL=''
_FROM=''
_TO=''
_CC=''
_BCC=''
_REPLY=''
_SUBJECT=''
_CHARSET=${MAILSEND_CHARSET}
_BODY=''
_TEXT=''
_STDIN=0
_ATTACH=''
_DIR=''
_REPOS='^.*$'
_RENEG='^$'
_MAILID=''
_SPOOLFILE=''
_BOUNDARY="----"`hexdump -e '"""%x"""' -n 16 /dev/random`"----"
usage ()
{
echo 'usage: mailsend [-A account] \'
echo ' -m "mailfile"'
echo ' mailsend [-A account] \'
echo ' -t "to address" \'
echo ' -s "subject" \'
echo ' [-f "from address"] \'
echo ' [-c "cc address"] \'
echo ' [-b "bcc address"] \'
echo ' [-r "reply-to address"] \'
echo ' [-B "body file"] \" \'
echo ' [-a [MIME-Type:]attachment file] \'
echo ' [-d directory [-i regex-include] [-e regex-exclude]] \'
echo ' [-C charset] \'
echo ' [ \"body text\"] \'
echo ' or read mail from STDIN (see documentation)'
}
# test_arg (flag, value)
test_arg ()
{
local _arg1=$1
local _arg2=$2
if [ "${_arg2}" != "" ]
then
case "${_arg1}"
in
"-A"|"--account")
_ACCOUNT=${_arg2}
;;
"-m"|"--mailfile")
_MAIL="${_arg2}"
;;
"-f"|"--from")
_FROM="${_arg2}"
;;
"-t"|"--to")
if [ "${_TO}" = "" ]
then
_TO="${_arg2}"
else
_TO="${_TO},${_arg2}"
fi
;;
"-c"|"--cc")
if [ "${_CC}" = "" ]
then
_CC="${_arg2}"
else
_CC="${_CC},${_arg2}"
fi
;;
"-b"|"--bcc")
if [ "${_BCC}" = "" ]
then
_BCC="${_arg2}"
else
_BCC="${_BCC},${_arg2}"
fi
;;
"-r"|"--reply-to")
_REPLY="${_arg2}"
;;
"-s"|"--subject")
_SUBJECT="${_arg2}"
;;
"-B"|"--body")
_BODY="${_arg2}"
;;
"-a"|"--attach")
if [ "${_ATTACH}" = "" ]
then
_ATTACH="${_arg2}"
else
_ATTACH="${_ATTACH};${_arg2}"
fi
;;
"-d"|"--dir")
_DIR="${_arg2}"
;;
"-i"|"--include")
_REPOS="${_arg2}"
;;
"-e"|"--exclude")
_RENEG="${_arg2}"
;;
"-C"|"--charset")
_CHARSET="${_arg2}"
;;
*)
echo "arg1 ${_arg1}"
break 2
;;
esac
return 0
else
echo "arg2 ${_arg1}"
fi
return 1
}
# key_value (key, value)
key_value ()
{
echo -n "${1}: "
shift
echo $@ | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/[[:space:]]*,[[:space:]]*/, /g'
}
mail_header ()
{
_n=$(get_account $_ACCOUNT)
_date=`date '+%a, %d %b %Y %H:%M:%S %z'`
_from=${_FROM}
if [ "${_from}" = "" ]
then
eval _from='${MAILSEND_'$_n'_FROM}'
if [ "${_from}" = "" ]
then
eval _from='${MAILSEND_'$_n'_SMTP_USERNAME}'
fi
fi
key_value "From" "${_from}"
key_value "To" "${_TO}"
if [ "${_REPLY}" != "" ]
then
key_value "Reply-To" "${_REPLY}"
fi
if [ "${_CC}" != "" ]
then
key_value "Cc" "${_CC}"
fi
if [ "${_BCC}" != "" ]
then
key_value "Bcc" "${_BCC}"
fi
# Subject-Kodierung herstellen
local _subject=`echo "${_SUBJECT}" | qprint -e`
if [ "${_subject}" = "${_SUBJECT}" ]
then
echo -e "Subject: ${_SUBJECT}"
else
echo -e "Subject: =?${MAILSEND_CHARSET}?Q?${_subject}?="
fi
echo -e "X-Sender: fli4l-mailsend"
echo -e "Date: ${_date}"
echo -e "Message-ID: <${_MAILID}.${_from}>"
}
mail_content ()
{
echo -e "MIME-Version: 1.0"
echo -e "Content-Type: multipart/mixed; boundary=\"${_BOUNDARY}\""
echo -e ""
echo -e "This is a MIME encapsulated multipart message -"
echo -e "please use a MIME-compliant e-mail program to open it."
echo -e ""
echo -e "--${_BOUNDARY}"
echo -e "Content-Type: text/plain; charset=\"${_CHARSET}\""
echo -e "Content-Transfer-Encoding: quoted-printable"
echo -e ""
}
mail_footer ()
{
echo -e "--${_BOUNDARY}--"
echo -e ""
}
mail_body ()
{
if [ "${_BODY}" != "" ]
then
cat "${_BODY}" | qprint -e
else
if [ $_STDIN -eq 0 ]
then
echo "${_TEXT}" | qprint -e
else
while read _line
do
if [ "${_line}" = "." ]
then
break 2
fi
echo "${_line}" | qprint -e
done
fi
fi
echo -e ""
}
# mail_attach (file)
mail_attach ()
{
_file=$1
_type=`echo "${_file}" | sed 's/^\(.*\):\(.*\)/\1/g'`
_file=`echo "${_file}" | sed 's/^\(.*\):\(.*\)/\2/g'`
if [ "${_type}" = "${_file}" ]
then
_type=`/usr/bin/file -i "${_file}" | cut -d ':' -f 2`
fi
_base=`basename "${_file}"`
echo -e "--${_BOUNDARY}"
echo -e "Content-Type:${_type}; name=\"${_base}\""
echo -e "Content-Disposition: attachment"
echo -e "Content-Transfer-Encoding: base64"
echo -e ""
base64 "${_file}"
echo -e ""
return 1
}
mail_files ()
{
if [ "${_ATTACH}" != "" ]
then
_count=0
while [ 1 ]
do
_count=$((_count + 1))
_file=`echo ${_ATTACH} | cut -d ';' -f ${_count}`
if [ "${_file}" = "" ]
then
break 2
fi
mail_attach "${_file}"
if [ "${_file}" = "${_ATTACH}" ]
then
break 2
fi
done
fi
}
mail_dir ()
{
if [ "${_DIR}" != "" ]
then
_act=`pwd`
cd ${_DIR}
for _file in `ls "${_DIR}"`
do
_file=`echo "${_file}" | grep ${_REPOS}`
if [ "${_file}" != "" ]
then
_temp=`echo "${_file}" | grep ${_RENEG}`
if [ "${_temp}" != "" ]
then
_file=""
fi
fi
if [ "${_file}" != "" ]
then
mail_attach "${_DIR}/${_file}"
fi
done
cd ${_act}
fi
}
spool_name ()
{
_timestamp=`date +%Y%m%d%H%M%S`
_random=`hexdump -e '"""%x"""' -n 4 /dev/random`
_MAILID="${_timestamp}.${_random}"
_spoolfile="${MAILSEND_SPOOL_DIR}/${_ACCOUNT}-${_MAILID}"
_SPOOLFILE="${_spoolfile}.mail"
}
variant_args ()
{
# check address arguments
if [ "${_TO}" = "" ]
then
return 1
fi
# check body arguments
if [ "${_BODY}" = "" -a "${_TEXT}" = "" -a $_STDIN -eq 0 ]
then
return 1
fi
if [ "${_BODY}" != "" -a "${_TEXT}" != "" ]
then
return 1
fi
if [ "${_BODY}" != "" -a $_STDIN -ne 0 ]
then
return 1
fi
if [ "${_TEXT}" != "" -a $_STDIN -ne 0 ]
then
return 1
fi
# create spool file name
spool_name
# create mailfile
mail_header > ${_SPOOLFILE}
mail_content >> ${_SPOOLFILE}
mail_body >> ${_SPOOLFILE}
mail_files >> ${_SPOOLFILE}
mail_dir >> ${_SPOOLFILE}
mail_footer >> ${_SPOOLFILE}
return 0
}
variant_file ()
{
# check address arguments
if [ "${_FROM}" != "" -o "${_TO}" != "" -o "${_CC}" != "" -o "${_BCC}" != "" -o "${_REPLY}" != "" ]
then
return 1
fi
# check body arguments
if [ "${_BODY}" != "" -o "${_TEXT}" != "" -o "${_SUBJECT}" != "" ]
then
return 1
fi
# check attachment arguments
if [ "${_ATTACH}" != "" -o "${_DIR}" != "" ]
then
return 1
fi
# create spool file name
spool_name
cp ${_MAIL} ${_SPOOLFILE}
return 0
}
send ()
{
if [ "${MAILSEND_SEND_DELAYED}" = "yes" ]
then
_spoolfile=`echo "${_SPOOLFILE}" | sed -e 's/\(.*\)\.mail$/\1.retry0/'`
mv ${_SPOOLFILE} ${_spoolfile}
else
mailsend-send.sh "${_SPOOLFILE}"
if [ -e "${_SPOOLFILE}" ]
then
_spoolfile=`echo "${_SPOOLFILE}" | sed -e 's/\(.*\)\.mail$/\1.retry1/'`
mv ${_SPOOLFILE} ${_spoolfile}
fi
fi
}
# read arguments
while test $# -gt 1
do
test_arg "$1" "$2"
if [ $? -ne 0 ]
then
usage
exit 1
fi
shift
shift
done
if [ $# -eq 0 ]
then
if [ "${_BODY}" = "" ]
then
_STDIN=1
fi
else
_TEXT=$1
fi
if [ "${_MAIL}" = "" ]
then
variant_args
else
variant_file
fi
if [ "$?" = "1" ]
then
usage
exit 1
fi
chmod 666 ${_SPOOLFILE}
#cat ${_SPOOLFILE}
send
exit 0
Mehr Informationen über die Mailingliste Fli4l_dev