Sending emails with dma

I am looking at using dma as the replacement for the removed sendEmail from IPFire. According to the dma Wiki I should be able to send a test message from the command line with:

sendmail.dma -s “DMA test mail” me@my.domain
This is a test mail
enter Control+D on a new line to send it.

This results in an error: invalid argument: `-s - which should set the subject line in the email.

I can send test messages from the mail.cgi page OK and send test messages without the subject line (-s) from the command line but are then blocked by spamassassin due to the missing Subject Line by the server.

Has anyone successfully sent emails with a ‘Subject Line’ from the command line with dma ? If this isn’t possible then perhaps we should retain sendEmail which works without difficulty.

Regards

Rob

Hi,

this information seems to be outdated. At least on dma’s manpage -s does not appear (anymore).

Could you try passing the Subject header via the message body such as this:

$ sendmail random.person@example.com <EOF
From: "Me, Myself and I" <john.doe@example.com>
To: "Random Person" <random.person@example.com>
Subject: "Subject line goes here"
Date: Sat,  3 Jul 2021 06:30:03 +0000 (UTC)
[other headers]

[body content]

EOF

Rather hacky, I guess, and you will probably have to take care of Message-ID and other fields on your own. However, there has to be a better way for doing this. Let me skim though our CGI file, and report back…

Thanks, and best regards,
Peter Müller

Thank you for your suggestion Peter, I have managed to send a test message with the Subject line sent locally.
It seems that dma unlike its predecessor sendEmail hasn’t the provision for formatting the email so I had to create an email as as temporary file as your suggestion (/tmp/email.test) such as this:

From: root@ipfire-dev.my.domain
To: me@my.address
Subject: “Test with dma”
Date: Sat, 3 Jul 2021 15:25:03 +0000 (UTC)

test2 from dma on ipfie-dev

and send it with this:

cat /tmp/email.test | sendmail me@my.address

dma seems to happily generate a message ID but I’ll need a way of generating the Date: header dynamically since the date is copied from the file.

I currently use sendEmail to send my logs to dshield using a hacked IPCop addon - logsend. It may be easier for me to import a local version of sendEmail after it has been removed from the available addons in IPFire rather than further modify logsend to use dma.

Thank you for your help

Rob

You could, but I would advise against it. sendEmail has not been under active development for many many years and the website has been taken down, too.

This is outdated and unmaintained software which is why we removed it. It is dangerous to be used.

dma is maintained and comes with more features. It however requires are valid email as input.

I understand your advice but, as I have found, dma is not a direct replacement for sendEmail as it looks like it requires a front end to format the email before dma can send it.

Looking at the mail.cgi page it looks like IPFire uses perl modules as the front end to dma. I have to wonder what use that page is since all it seems to be capable of is sending test messages and not doing anything particularly useful, or perhaps I have missed something!

Rob

dma is an MTA (which is what you want here). It would really try to deliver that email, even if the SMTP server was unavailable.

sendEmail is more of a MUA. It tries to connect to the server, but if anything goes wrong you are not receiving an email ever.

That is why we went with dma. It would be great if would be easier to send rich emails from the console, but this is generally not in scope of any MTA (Postfix, exim, etc.) do not have this functionality either. But the Python standard library allows composing emails in very few lines and Perl has modules for that, too. It doesn’t take more than a couple of lines.

Currently only a few add-ons are using this functionality. We always wanted to extend this, but time is tight.

I am aware of the MUA / MTA differences, in my unusual case I have a mail server running sendmail and dovecot on a different computer which handles all my internal and external email so errors are handled by that computer, so an MUA works fine for me and dma is a bit of an overkill for my network.

I’ll look into writing a perl program. I see perl module MIME::Lite is available so maybe I can use that.

Incidently when my server was bouncing some of my erroneous attempts to use dma with the -s switch, dma was producing log file errors:

“ trying delivery
local delivery deferred: can not create /var/mail/root' error creating mbox root’
cannot execute /usr/lib/dma-mbox-create: No such file or directory”

After I manually created /var/log/root, dma was able to deliver the bounces to that file and the error messages stopped.
That maybe there is a bug with dma (probably permissions) which may need addressing sometime.

Thank you for your help

Rob

Hi Micael,
I’m fully with your tactics to move away from software, which hasn’t been progressed for a while.
Nevertheless, I tried to migrate sending file attachments to DMA. Unfortunately I could find any variable supporting this. Also using the file content as mail body didn’t worked out so far.

Any idea how to realise this functionality with the DMA?

Best regards & thanx for all your great work

I used that too: it fixed also tons of logs I saw generated by my DMA after doing 15-20 APCUPSD tests to send e-mails for its major events…

But I also had to create /var/mail/nobody since my APCUPSD sends messaged as “nobody” user…

I ended up using this shell script to send my firewall reports to dshield which you may find helpful. This has been running without any problem over the last year. The script formats the email and sends it via /usr/sbin/sendmail. Remember you need to set up a working mail server address in IPfire’s mail service tab. Using this I didn’t need to create the /var/mail/root directory.

…
#!/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@dshield.org
sender=dshield@domain

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

function mail_input {
echo -ne “From: dshield@domain\r\n”
echo -ne “To: <$recipient>\r\n”
echo -ne “Subject: FORMAT IPTABLES USERID xxxxxxx 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 -f $sender $recipient

/bin/rm /var/tmp/dshield.mail

fi

else
exit 0
fi
…

Rob

Sorry to bring this back to life, but it seems to be the most appropriate place to ask this question.

My /var/log/mail contains hourly log entries as follows:

Nov 16 14:00:00 ipfire dma[10044b.9e7e8c0]: <root> trying delivery
Nov 16 14:00:00 ipfire dma[10044b.9e7e8c0]: cannot execute /usr/lib/dma-mbox-create: No such file or directory
Nov 16 14:00:00 ipfire dma[10044b.9e7e8c0]: error creating mbox `root'
Nov 16 14:00:00 ipfire dma[10044b.9e7e8c0]: local delivery deferred: can not create `/var/mail/root'
Nov 16 14:00:00 ipfire dma[10044b.9e7e8c0]: can not bounce a bounce message, discarding
Nov 16 15:00:00 ipfire dma[10044b.9e7e8c0]: <root> trying delivery
Nov 16 15:00:00 ipfire dma[10044b.9e7e8c0]: cannot execute /usr/lib/dma-mbox-create: No such file or directory
Nov 16 15:00:00 ipfire dma[10044b.9e7e8c0]: error creating mbox `root'
Nov 16 15:00:00 ipfire dma[10044b.9e7e8c0]: local delivery deferred: can not create `/var/mail/root'
Nov 16 15:00:00 ipfire dma[10044b.9e7e8c0]: can not bounce a bounce message, discarding

/var/mail/root exists and has the following properties:

# ls -l /var/mail/root
-rw-r--r-- 1 root mail 0 Oct 27 22:25 /var/mail/root

What should the file permissions and ownership be?

Also, there’s a reference to creating a file /var/log/root above. Is that a typo? Did @helix intend to say /var/mail/root?

Then you have created that yourself, unless you are running with the unstable CU199.

In CU198 that directory was not created because the binary dma-mbox-create was not installed.

Back at the end of September a patch was merged into what will become CU199 that installs the dma-mbox-create binary.

Thank you for the prompt reply! I ought to have said which version of IPFire I’m running:

2.29 (x86_64) - Core-Update 198

So what’s to be done? Do I sit tight until 199 arrives?

What about that reference to /var/log/root?

@helix needs to respond to that. I can’t answer if that is a typo or intended.

Those bounced emails are all because you have some error somewhere. They can be ignored so just wait for CU199 to be released.

If you want to deal with them then you need to do an install of CU199 in some system and you can then copy across the file from

usr/lib/dma-mbox-create

to your CU198 system.

Just for information

The IPFire Mail Service configuration page — /cgi-bin/mail.cgi sends a test e-mail using MIME::Lite.

However

MIME::Lite is not recommended by its current maintainer. There are a number of alternatives, like Email::MIME or MIME::Entity and Email::Sender, which you should probably use instead. MIME::Lite continues to accrue weird bug reports, and it is not receiving a large amount of refactoring due to the availability of better alternatives. Please consider using something else.

Regards

Just a reminder

Recently, the topic of sending messages using DMA, workarounds and error solutions was discussed in the following threads

https://community.ipfire.org/t/new-reports-addon/14312/33?u=tphz (This post and subsequent posts in this thread)

Regards

I don’t have /var/log/root or /var/spool/root on either of my CU188 or CU198 installations. I am still using the shell script shown above without errors run as root and also a similar perl script again run as root.

Typical entries to /var/log/mail are:

Nov 17 16:01:00 griffith6 dma[1b0f]: new mail from user=root uid=8 envelope_from=
Nov 17 16:01:00 griffith6 dma[1b0f]: mail to= queued as 1b0f.ca3a80
Nov 17 16:01:00 griffith6 dma[1b0f.ca3a80]: trying delivery
Nov 17 16:01:00 griffith6 dma[1b0f.ca3a80]: using smarthost (x:25)
Nov 17 16:01:00 griffith6 dma[1b0f.ca3a80]: trying remote delivery to x [192.168.0.4] pref 0
Nov 17 16:01:00 griffith6 dma[1b0f.ca3a80]: Server greeting successfully completed
Nov 17 16:01:00 griffith6 dma[1b0f.ca3a80]: Server supports STARTTLS
Nov 17 16:01:00 griffith6 dma[1b0f.ca3a80]: Server supports LOGIN authentication
Nov 17 16:01:00 griffith6 dma[1b0f.ca3a80]: SSL initialization successful
Nov 17 16:01:00 griffith6 dma[1b0f.ca3a80]: Server greeting successfully completed
Nov 17 16:01:00 griffith6 dma[1b0f.ca3a80]: Server does not support STARTTLS
Nov 17 16:01:00 griffith6 dma[1b0f.ca3a80]: Server supports LOGIN authentication
Nov 17 16:01:03 griffith6 dma[1b0f.ca3a80]: delivery successful

So I would think the errors are coming from dma-mbox-create which isn’t present of either of my installations.

My perl email script can be found in the ‘sub mail’ section here:

https://people.ipfire.org/~helix/auto-dnsbl/auto-dnsbl.pl