Core Update 158: SendEmail will be removed

In the command that you are using to send the information to dma you need to include the -f option.
The -r option is the same as the -f option so either can be used

-f mickey.mouse@gmx.de
1 Like

Hi Adolf, much appreciate your help!
For everyone else: you need the -f option but you also need to put a “From: mickey.mouse@gmx.de” in the text editor.

So the full command in my case:
sudo -u nobody dma -f ‘mickey.mouse@gmx.de’ mickey.mouse@gmx.de [Which starts the “editor”]
From: mickey.mouse@gmx.de
. [To terminate the editor]

Hope this helps.

Hi Peter,

Sorry, I thought you already had the From in your text. The -f makes dma set the envelope to the specified address. Without it dma will set the envelope to the user sending the email which will be the user nobody.

My test script I have created for sending apcupsd status reports is the following

#!/bin/bash

/sbin/apcaccess status > ~/apc.status
body_text=$(echo "\r\n"; while read line; do echo "$line\r\n"; done < ~/apc.status)

function mail_input {
echo From: name-you-are-sending-from
echo To: name-you-are-sending-to
echo Subject: Subject text where special characters need to be escaped
echo -ne $body_text
}

mail_input | /usr/sbin/sendmail -t -f name-you-are-sending-from

This is based on @helix script but his didn’t work for me as written. The above worked for me and the whole of the multiline content of $email is in the body of the email. I will be integrating this into the apcupsd scripts on my system so that any warnings will be sent as emails.

The bash script I suggested in my case is run from fcron as root so maybe that is why you are having permission problems. I don’t use the -f or -t switch either.
I have been using my script for the last month to send my logs to dshield through dma but I only send a text body (not html).

This is my working script:

#!/bin/bash

if [ -f /var/ipfire/red/active ]; then
if [ -f /var/tmp/dshield.mail ]; then

now=$(/bin/date -R)
random=$(/usr/bin/tr -dc ‘a-zA-Z0-9’ < /dev/urandom | /usr/bin/fold -w 12 | /bin/head -n 1)
messageid=$(/bin/date --utc +%Y%m%d%H%M%S.$random@$HOSTNAME)
email=$(/bin/cat /var/tmp/dshield.mail)
recipient=report@xxxx.org

function err_exit() { echo -e 1>&2; exit 1; }
function mail_input {
echo -ne “From: dshield@my.domain\r\n”
echo -ne “To: <$recipient>\r\n”
echo -ne “Subject: FORMAT IPTABLES USERID 78507304 TZ GMT\r\n”
echo -ne “Message-Id: <$messageid>\r\n”
echo -ne “Date: $now\r\n”
echo -ne “\r\n”
echo -ne “$email\r\n”
echo -ne “.\r\n”
}

mail_input | /usr/sbin/sendmail $recipient
rm /var/tmp/dshield.mail
fi
else
exit 0
fi

and dma logs:
|16:01:08|dma[26ce.8620cb0]:expressionless:report@xxxx.org delivery successful|
|16:01:01|dma[26ce.8620cb0]:|Server supports CRAM-MD5 authentication|
|16:01:01|dma[26ce.8620cb0]:|Server does not support STARTTLS|
|16:01:01|dma[26ce.8620cb0]:|Server greeting successfully completed|
|16:01:00|dma[26ce.8620cb0]:|trying remote delivery to me@me [192.168.0.3] pref 0|
|16:01:00|dma[26ce.8620cb0]:|using smarthost (local.address:25)|
|16:01:00|dma[26ce.8620cb0]:expressionless:report@xxxx.org trying delivery|
|16:01:00|dma[26ce]:|mail to=report@xxxxx.org queued as 26ce.8620cb0|
|16:01:00|dma[26ce]:|new mail from user=root uid=8 envelope_from=root@me.at.my.domain|

Hope this helps

Rob (Helix)

1 Like