Core Update 158: SendEmail will be removed

Hi,

I just noticed in the release note of the Core Update of 158, that the command “sendEmail” will be removed.

I check my automation program FHEM and saw, that I am using the following command to
inform me about problems of the system by eMail.

$ret .= qx(/usr/local/bin/sendEmail -f ‘$sender’ -t ‘$rcpt’ -u ‘$subject’ -m ‘$text’ -s ‘$provider’ -xu ‘$konto’ -xp ‘$passwrd’ -o tls=yes);

I guess, after the update to core 158, this function will no longer work.
Is there a similar function existing or do I have to add this function manually to my system.

Thanks for help

Best regards
R.

The following thread might help you.

https://community.ipfire.org/t/sending-emails-with-dma/5734

2 Likes

Hi Ritchie,

I am using this code below in a bash script and seems to work OK. You need to generate the date and message-id headers, unless you can get your smart-host generate them for you. I’ve not tried it with TLS but I think it would work if you added the appropriate headers.

The other possibility is to use perl with the MIME::Lite module. Have a look at mail.cgi testmail section for inspiration.

Rob

#!/bin/bash

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 /your.data)
recipient=“someone@somewhere”

function err_exit() { echo -e 1>&2; exit 1; }

function mail_input {
echo -ne “From: me@myplace\r\n”
echo -ne “To: <$recipient>\r\n”
echo -ne “Subject: Your Subject\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

fi

else
exit 0
fi

1 Like

Hello,
thanks for the information.
@bonnietwin
Will will give the sendmail (dma) a chance and will see how I have to create a perl function to
get it run.
Best regards
R.

Hi,

i will get the following message, when I try to send a eMail
from my automation system.

sendmail: can not open auth file `/var/ipfire/dma/auth.conf’: Permission denied

I am using this command

open(MAIL, “|/usr/sbin/sendmail -t”);
print MAIL “To:”.$to.“\n”;
print MAIL “From:”.$from.“\n”;
print MAIL “Subject:”.$subject.“\n”;
print MAIL “Message-Id: <”.$messageid.“>\n”;
print MAIL “Date:”.$DateTimeValue.“\n”;
print MAIL “Content-type: text/html\n\n”;
print MAIL $message;
close(MAIL);

Here the permission of the files:

[root@ipfire log]# ls -al /var/ipfire/dma
total 16
drwxr-xr-x 2 nobody nobody 4096 Jul 9 2020 .
drwxr-xr-x 51 root root 4096 Jun 22 00:46 …
-rw-r----- 1 nobody root 220 Jul 25 19:56 auth.conf
-rw-r–r-- 1 nobody nobody 2363 Jul 25 20:00 dma.conf
-rw-r–r-- 1 nobody nobody 0 Dec 3 2015 mail.conf
[root@ipfire log]#

How can I solve this ?

Best regards
R.

FWIW, mine look like this:

-rw-r----- 1 nobody mail 43 May 8 10:12 auth.conf
-rw-r–r-- 1 nobody nobody 159 May 8 10:12 dma.conf
-rw-r–r-- 1 nobody nobody 72 May 8 10:12 mail.conf

Note the difference on auth.conf

Interesting.

Mine matches Ritchie’s setup

-rw-r-----  1 nobody root     43 Aug 13  2020 auth.conf
-rw-r--r--  1 nobody nobody  170 Aug 13  2020 dma.conf
-rw-r--r--  1 nobody nobody   73 Aug 13  2020 mail.conf

I haven’t yet tried sending emails with a command but it is on my list of things to do so I can get apcupsd to send status change emails.

I had to change the permissions on auth.conf. to "nobody mail ". Before making the change, I was getting the same error “sendmail: can not open auth file `/var/ipfire/dma/auth.conf’: Permission denied” as @ritchie

Mine matches also:

[root@ipfire ~]# ls -al /var/ipfire/dma
total 20
drwxr-xr-x  2 nobody nobody 4096 Jul 21 14:21 .
drwxr-xr-x 48 root   root   4096 Jul 15 14:51 ..
-rw-r-----  1 nobody root     43 Mar 17  2019 auth.conf
-rw-r--r--  1 nobody nobody  159 Mar 17  2019 dma.conf
-rw-r--r--  1 nobody nobody   70 Mar 17  2019 mail.conf

FYI - when I went to menu SystemMail Service and clicked on Send test mail I get these log entries.

The bottom line in the code block states new mail from user=nobody.

And as a side note - There is an attempt to send via IPv6: trying remote delivery to smtp.gmail.com [2607:x8x0:4001:x07::6x] pref 0.

IPFire diagnostics
Section: dma
Date: July 30, 2021

18:53:24 dma[300824.1498640]:  <[redacted]@gmail.com> delivery successful
18:53:23 dma[300824.1498640]:  using SMTP authentication for user [redacted]
18:53:23 dma[300824.1498640]:    Server supports LOGIN authentication
18:53:23 dma[300824.1498640]:    Server does not support STARTTLS
18:53:23 dma[300824.1498640]:  Server greeting successfully completed
18:53:23 dma[300824.1498640]:  SSL initialization successful
18:53:23 dma[300824.1498640]:    Server supports STARTTLS
18:53:23 dma[300824.1498640]:  Server greeting successfully completed
18:53:23 dma[300824.1498640]:  trying remote delivery to smtp.gmail.com [108.177.111.109] pref 0
18:53:23 dma[300824.1498640]:  connect to smtp.gmail.com [2607:x8x0:4001:x07::6x] failed: Cannot assign requested address
18:53:23 dma[300824.1498640]:  trying remote delivery to smtp.gmail.com [2607:x8x0:4001:x07::6x] pref 0
18:53:23 dma[300824.1498640]:  using smarthost (smtp.gmail.com:587)
18:53:23 dma[300824.1498640]:  <[redacted]@gmail.com> trying delivery
18:53:23 dma[300824]:  mail to=<[redacted]@gmail.com> queued as 300824.1498640
18:53:23 dma[300824]:  new mail from user=nobody uid=99 envelope_from=<[redacted]@gmail.com>

It’s been a while ago but as I recall, I was having the permission problem on auth.conf when mail was getting sent from either the swatch daemon or apcupsd – not from the WUI Send Test Mail method

Hi,

after I changed the permission of the file, I will no get the permission failure again.
Do I have to change the permission after the next updated again?

But now I get the following message:

failed after MAIL FROM: 550-Req uested action not taken: mailbox unavailable^M 550 invalid DNS MX or A/AAAA reso urce record

I guess the messageid is not proper setup.

The test email from the Web GUI of IPfire is working well, I will get the eMail.

Best regards
R.

It seems the permission change I made has been sticking across that past few updates.

That would likely change when dma gets updated next.

I think a better solution rather than changing the group of auth.conf is to run the command you are using as the user nobody as that is what dma is run as. That should be able to work by running the command /usr/sbin/sendmail by

sudo -u nobody /usr/sbin/sendmail

alternatively us su to change to user nobody and then run the sequence of commands that Ritchie had in post 5 and then exit from su.

Alternatively put any commands into a script and then run that script as the user nobody, either with sudo or su.

I will give that a try when I have a go at getting apcupsd email notifications working.

EDIT:
I just tried running /usr/sbin/sendmail using my additional user that I created in IPFire and I got the following

sendmail: can not open auth file `/var/ipfire/dma/auth.conf': Permission denied

I then tried sudo -u nobody /usr/sbin/sendmail and got

sendmail: no recipients

which is expected as I didn’t add any info to the sendmail command but it didn’t come up with the Permission denied response. So I think this approach should be able to work without needing to change the ownership of any of the files.

Hi,

Up to now I am using this type of script:

sub DebianMailNew
{
my $to = shift;
my $subject = shift;
my $message = shift;
my $from;
my $msg;

$from = “emailadress@provider.de”;

Create a new multipart message:

$msg = MIME::Lite->new(
	From	=> $from,
	To		=> $to,
	Subject	=> $subject,
	Type	=> 'multipart/mixed'
) or die "Error creating multipart container: $!\n";

### Add parts (each "attach" has same arguments as "new"):
$msg->attach(
	Type	=> 'TEXT',
	Data	=> $message
) or die "Error adding the text message part: $!\n";

$msg->send_by_sendmail;	
return;

}

I am still fighting with the warning message
“error closing /usr/sbin/sendmail: No child processes (exit -1)”
until I can release this function and switch to the new core update.

Best regards
R.

@bonnietwin let me know when you get apcupsd running as nobody. That’s sort of beyond the scope of my simple caveman brain :sunglasses: . I also get mail sent from swatchdog daemon. Note both currently run as root:

root 4531 1 0 Jul20 ? 00:01:47 apcupsd
root 4545 1 0 Jul20 ? 00:00:00 /usr/bin/swatchdog

-cb

Ah, apcupsd doesn’t have to run as nobody, it is the command used to send the mail message that needs to be run as nobody.

I will start a new thread when I am successful with apcupsd messaging.

I have been successful in sending myself an email via dma without changing the group ownership of auth.conf. I need to do some more work as the subject line ended up empty and the body had the from line in it and no newlines in the body portion I defined but it is making progress.

Once I have a fully successful command line email sent I will show what I used.

Okay, I found where apcupsd is calling sendmail in /etc/apcupsd/apccontrol. I suppose I could modify those lines to add sudo -u nobody to the front of those commands. On the other hand, swatchdog appears a little more opaque. Since I am starting it from /etc/sysconfig/rc.local, I suppose i could try launching it as user nobody. I’ll let you know how it goes :cowboy_hat_face:

Edit: Okay that all sort of works using the default permissions on auth.conf. On the other hand, running swatchdog as user nobody has an issue writing the /var/run/swatch.pid file. So, I tweaked the startup to touch and chown the pid file so it could be written to by nobody. Other than that all seems to be working nominally. Thanks @bonnietwin

-cb

1 Like

Hi @cbrown

Great to hear that you got the email communication from apcupsd working :+1: :+1:. Gives me good confidence for when I have a go at setting it up.

I have no experience with regard to swatchdog so can’t give any specific help on that front.

1 Like

Hello Adolf,

maybe I have to plan the same stuff to switch over to “nobody” for my
automation software. It is based on FHEM and using a little bit more than
a ups.
http://fhem.de/fhem.html
In addition, I guess this is also not the right thread for a answer.
But I will check, how I can switch over. I will be a secure
issue as well. Up to now I have my own user with additional rights to handle
the system.

Best regards
R.

Hi all,

quite frustrating to see that the sendMail addon was abandone without offering a proper alternative.

dma seems to come close, thank you for the above helpful information.
Unfortunately, I cannot get IPfire to send an email using a gmx.de account.

My mail service is properly setup, IPfire sends a test mail via the WEB gui.
My dma configuration files in /var/ipfire/dma look OK per the comments above:
-rw-r----- 1 nobody root 46 Aug 24 23:04 auth.conf
-rw-r–r-- 1 nobody nobody 152 Aug 24 23:04 dma.conf
-rw-r–r-- 1 nobody nobody 68 Aug 24 23:04 mail.conf

This are the error logs in /var/log/mail:
Aug 24 23:33:12 FWB dma[74000e]: new mail from user=nobody uid=99 envelope_from=nobody@FWB.fritz.box
Aug 24 23:33:12 FWB dma[74000e]: mail to=mickey.mouse@gmx.de queued as 74000e.495290
Aug 24 23:33:12 FWB dma[74000e.495290]: mickey.mouse@gmx.de trying delivery
Aug 24 23:33:12 FWB dma[74000e.495290]: using smarthost (mail.gmx.net:587)
Aug 24 23:33:12 FWB dma[74000e.495290]: trying remote delivery to mail.gmx.net […] pref 0
Aug 24 23:33:12 FWB dma[74000e.495290]: Server greeting successfully completed
Aug 24 23:33:12 FWB dma[74000e.495290]: Server supports STARTTLS
Aug 24 23:33:12 FWB dma[74000e.495290]: SSL initialization successful
Aug 24 23:33:13 FWB dma[74000e.495290]: Server greeting successfully completed
Aug 24 23:33:13 FWB dma[74000e.495290]: Server does not support STARTTLS
Aug 24 23:33:13 FWB dma[74000e.495290]: Server supports LOGIN authentication
Aug 24 23:33:13 FWB dma[74000e.495290]: using SMTP authentication for user mickey.mouse@gmx.de
Aug 24 23:33:13 FWB dma[74000e.495290]: remote delivery to mail.gmx.net […] failed after MAIL FROM: 550-Requested action not taken: mailbox unavailable^M 550 invalid DNS MX or A/AAAA resource record
Aug 24 23:33:13 FWB dma[74000e.495290]: delivery failed, bouncing as 7403c8
Aug 24 23:33:13 FWB dma[7403c8]: new mail from user=nobody uid=99 envelope_from=<>
Aug 24 23:33:13 FWB dma[7403c8]: mail to= queued as 7403c8.4d5f30
Aug 24 23:33:13 FWB dma[7403c8.4d5f30]: trying delivery
Aug 24 23:33:13 FWB dma[7403c8.4d5f30]: delivery successful

I assume the issue is the first line, the envelope_from does not show my correct gmx email address mickey.mouse@gmx.de but a local email address:
Aug 24 23:33:12 FWB dma[74000e]: new mail from user=nobody uid=99 envelope_from=nobody@FWB.mylocaldomain

I could not find a way to set the “from” address properly.

Best Regards
Peter