Ubuntu – How to customize unattended-upgrades notification emails

unattended-upgrades

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?

Best Answer

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.