Sample Header Ad - 728x90

How to use s-nail with unattended-upgrades?

5 votes
1 answer
4746 views
My ISP blocks port 25 and I want to send email after unattended-upgrades completes. I set things up so that I can successfully send mail with s-nail, but unattended-upgrades still isn't sending me email and I don't know why. # s-nail setup First, the s-nail configuration. ### Installing s-nail I came across info for heirloom-mailx, but delving into it, the maintainers said, "ahh, you don't need that, just create a link from /usr/bin/mail to s-nail!" So that is what I did:
# first, uninstall any mailx programs you have
sudo apt remove bsd-mailx
sudo rm -f /usr/bin/mail  # just in case something is still installed

# install s-nail and link it
sudo apt install s-nail
sudo ln -s /usr/bin/s-nail /usr/bin/mail
### $HOME/.mailrc
v15-compat

from="CronUpdates "
sendwait
sendcharsets=utf-8,iso-8859-1

mta=smtp://cron%40mydomain.com:@smtppro.zoho.com:587 \
smtp-auth=login \
smtp-use-starttls
which is of course chmod 600 $HOME/.mailrc'd as it is supposed to be. ### $HOME/send_test_email.sh
#!/bin/bash

EMAIL_SUBJECT="Cron Email"
TO_ADDRESS="admin@mydomain.com"

echo 'Hello world!' | s-nail -s "$EMAIL_SUBJECT" "$TO_ADDRESS"
which is of course chmod u+x $HOME/send_test_email.sh'd, allowing us to:
./send_test_email.sh
# success!
Woo-hoo, I get an email! # unattended-upgrades setup Next, the unattended-upgrades configuration in /etc/apt/apt.conf.d/50unattended-upgrades. This represents an ubuntu configuration, but I have a raspberry pi configuration that is a little different, but has the same issue.
Unattended-Upgrade::Allowed-Origins {
  "${distro_id}:${distro_codename}";
  "${distro_id}:${distro_codename}-security";
  "${distro_id}ESMApps:${distro_codename}-app-security";
  "${distro_id}ESM:${distro_codename}-infra-security";
  "${distro_id}:${distro_codename}-updates";
};

Unattended-Upgrade::Package-Blacklist {
};

Unattended-Upgrade::DevRelease "auto";

Unattended-Upgrade::Mail "admin@mydomain.com";
Unattended-Upgrade::MailReport "always";
I can --dry-run unattended upgrades, *if there's anything to upgrade*, but I don't think that sends an email. Still, that's useful:
# do a dry-run to iron out any issues that you can with unattended-upgrades
sudo unattended-upgrades -v -d --dry-run

# doesn't send an email, but that's operating as designed :(
Then, *if there's anything to upgrade* (which makes everything very difficult to debug, especially since apt-cache madison only returns one result), I can drop --dry-run and it will allegedly attempt to send the email:
machine$ sudo unattended-upgrades -v -d
Running on the development release
Starting unattended upgrades script
Allowed origins are: o=Ubuntu,a=impish, o=Ubuntu,a=impish-security, o=UbuntuESMApps,a=impish-apps-security, o=UbuntuESM,a=impish-infra-security, o=Ubuntu,a=impish-updates
Initial blacklist:
Initial whitelist (not strict):
Marking not allowed  with -32768 pin

... many lines later ...

Package docker-ce-rootless-extras has a higher version available, checking if it is from an allowed origin and is not pinned down.
Extracting content from /var/log/unattended-upgrades/unattended-upgrades-dpkg.log since 2022-04-15 17:53:56
Sending mail to admin@mydomain.com
mail returned: 0
Oh no, I don't get any email! The above configuration represents many hours of research, trial, and error attempting to get both email and unattended-upgrades to work; both of which work, but now must work together... How can I make unattended-upgrades actually send its email given that I must use the .mailrc configuration defined above?
Asked by Erasmus (173 rep)
Apr 16, 2022, 01:31 AM
Last activity: Jan 19, 2023, 02:46 AM