14

Is there any way to customize the unattended-upgrades results mail in ubuntu?

The current configuration in /etc/apt/apt.conf.d/50unattended-upgrades file -

// Send email to this address for problems or packages upgrades
// If empty or unset then no email is sent, make sure that you 
// have a working mail setup on your system. The package 'mailx'
// must be installed or anything that provides /usr/bin/mail.
//Unattended-Upgrade::Mail "root@localhost";

sends an email on every run. Instead, I would like to customize it to send only on error. Is there any way I can configure that?

Braiam
  • 67,791
  • 32
  • 179
  • 269
Mayur
  • 213

2 Answers2

9

Don't know why they deleted this line on Ubuntu, but Debian includes:

// Set this value to "true" to get emails only on errors. Default
// is to always send a mail if Unattended-Upgrade::Mail is set
//Unattended-Upgrade::MailOnlyOnError "true";

If your /etc/apt/apt.conf.d/50unattended-upgrades don't include the line (and the changelog don't give away this change in presice) is very odd, but at least it doesn't say they changed the behavior. I use a slightly updated version (0.80~sid2 opposed to 0.79.3ubuntu4 that Ubuntu includes in the precise-updates repository) and it will send a mail only on errors (I hasn't get a mail for now). Just write the lines to your configuration file, and everything should be working:

Unattended-Upgrade::Mail "your@email.com";
Unattended-Upgrade::MailOnlyOnError "true";

You may want to run sudo unattended-upgrade -v -d --dry-run to check the entire process yourself.

Braiam
  • 67,791
  • 32
  • 179
  • 269
  • 1
    Ubuntu (at least some versions) seem to ignore this line: https://bugs.launchpad.net/ubuntu/+source/unattended-upgrades/+bug/1056104 – dtech Jul 24 '14 at 08:30
  • 1
    In 14.04 LTS, the line Unattended-Upgrade::MailOnlyOnError "true"; is back in /etc/apt/apt.conf.d/50unattended-upgrades. It's commented out by default. – azimut Oct 15 '14 at 09:06
  • 1
    note that multiple addresses can be used as well with: Unattended-Upgrade::Mail "root,someuser,your@email.com,others@somewhere.com"; – jimmont Oct 10 '16 at 18:17
  • 1
    Newer versions of unattended-upgrade no longer email if --dry-run is specified – lily Oct 01 '19 at 03:51
  • 1
    Indeed, how do we test this now? – Houman Nov 21 '20 at 12:32
  • How does the unattended upgrades send out the email? Do I need to setup any emailing software on the server? – xyz May 09 '23 at 07:16
  • @xyz it sends using sendmail. Whatever provides sendmail does it. – Braiam May 19 '23 at 15:44
  • To add some more context here, I got the following in my logs which explains which providers it tries: ERROR No /usr/bin/mail or /usr/sbin/sendmail, can not send mail. You probably want to install the mailx package. – xyz Aug 16 '23 at 09:03
1

Works as of Linux Mint 20 which is pretty much Ubuntu 20.04.
To quote the comments in the file

Set this value to one of:
"always", "only-on-error" or "on-change"
If this is not set, then any legacy MailOnlyOnError (boolean) value
is used to chose between "only-on-error" and "on-change"

Unattended-Upgrade::MailReport "only-on-error";
Default
  • 121