ServicesAboutGet Started
LinuxFedoraAutomation

DNF5 Automatic — Email Notifications via Microsoft Graph API or Amazon SES

Set up dnf5-automatic on Fedora 43+ to deliver package update reports by email using either Microsoft Graph API or Amazon SES via API.

All commands assume you are logged in as a non-root user with sudo access.


1. Install dnf5-automatic

bash
sudo dnf install -y dnf5-plugin-automatic

Using Amazon SES? You will also need the boto3 Python library:

bash
sudo dnf install -y python3-boto3

2. Copy the default configuration file

bash
sudo cp /usr/share/dnf5/dnf5-plugins/automatic.conf /etc/dnf/automatic.conf

3. Configure automatic.conf

Run the following commands to apply the required settings. Choose the block that matches your mail provider — the only difference is the command_format line.

Common settings (apply for both providers)

bash
# Enable automatic updates
sudo sed -i 's/^apply_updates = no$/apply_updates = yes/' /etc/dnf/automatic.conf

# Reboot when needed after updates
sudo sed -i 's/^reboot = never$/reboot = when-needed/' /etc/dnf/automatic.conf

# Shorten the reboot delay from 5 minutes to 1 minute
sudo sed -i "s/^reboot_command = \"shutdown -r +5/reboot_command = \"shutdown -r +1/" /etc/dnf/automatic.conf

# Route output through a custom command instead of stdio
sudo sed -i 's/^emit_via = stdio$/emit_via = command/' /etc/dnf/automatic.conf

# Uncomment and set stdin_format so the report body is piped to the command
sudo sed -i 's/^# stdin_format = "{body}"/stdin_format = "{body}"/' /etc/dnf/automatic.conf

Set the command for your mail provider

Microsoft Graph API:

bash
sudo sed -i 's|^# command_format = "cat"|command_format = /usr/local/sbin/dnf-auto-mail-api graph|' /etc/dnf/automatic.conf

Amazon SES:

bash
sudo sed -i 's|^# command_format = "cat"|command_format = /usr/local/sbin/dnf-auto-mail-api ses|' /etc/dnf/automatic.conf

4. Obtain API credentials

Before proceeding, gather the credentials for your chosen provider.

Microsoft Graph API

You will need an Entra ID (Azure AD) App Registration with the Mail.Send application permission granted (admin-consented). Collect:

ValueDescription
tenant_idYour Microsoft 365 tenant ID
client_idThe App Registration's Application (client) ID
client_secretA client secret generated for the App Registration
senderThe mailbox the Graph API will send from (e.g. noreply@domain.com)
email_fromThe address shown in the From header (usually the same as sender)
email_toSpace-separated list of recipient addresses

Amazon SES

You will need IAM credentials with ses:SendEmail permission. Collect:

ValueDescription
regionAWS region for SES (e.g. us-east-1)
aws_access_key_idIAM access key ID
aws_secret_access_keyIAM secret access key
aws_session_token(Optional) Session token if using temporary credentials
configuration_set(Optional) SES configuration set name
email_fromVerified sender address in SES
email_toSpace-separated list of recipient addresses

5. Create the credentials file

The credentials are stored in /root/.dnf-mail-api. Create the file with the appropriate section for your provider.

Microsoft Graph API

bash
sudo tee /root/.dnf-mail-api > /dev/null <<'EOF'
[graph]
tenant_id = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
client_id = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
client_secret = YOUR_SECRET_HERE
sender = noreply@domain.com
email_from = noreply@domain.com
email_to = someadmin@domain.com
subject_prefix = [HostName]
expire = 2028-03-31
EOF

Amazon SES

bash
sudo tee /root/.dnf-mail-api > /dev/null <<'EOF'
[ses]
region = us-east-1
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = YOUR_SECRET_KEY_HERE
email_from = noreply@domain.com
email_to = someadmin@domain.com
subject_prefix = [HostName]
expire = 2028-03-31
EOF
💡

Replace all placeholder values with your real credentials. The subject_prefix is prepended to every email subject — set it to something that identifies the host (e.g. [WebServer], [Relay]). The expire field is informational — use it to track when the client secret or IAM key needs to be rotated.

Lock down file permissions

bash
sudo chmod 600 /root/.dnf-mail-api

The dnf-auto-mail-api script enforces 0600 permissions and will refuse to run if the file is world- or group-readable.


6. Install the mail script

Download and deploy the dnf-auto-mail-api Python script to /usr/local/sbin/:

bash
sudo wget -O /usr/local/sbin/dnf-auto-mail-api https://meikakuconsulting.com/guides/dnf/dnf-auto-mail-api
sudo chmod 0750 /usr/local/sbin/dnf-auto-mail-api
sudo chown root:root /usr/local/sbin/dnf-auto-mail-api

Verify the script compiles

bash
sudo python3 -m py_compile /usr/local/sbin/dnf-auto-mail-api

If this command produces no output, the script is syntactically valid.


7. Enable and start the timer

bash
sudo systemctl enable --now dnf5-automatic.timer

This schedules dnf5-automatic to run on its default cadence (typically daily).


8. Test manually

To verify everything works end-to-end without waiting for the timer:

bash
sudo dnf5 automatic
💡

An email is only sent when there are updates to report. If the system is already fully current, the command will run and produce no output — this is normal.

To validate the email pipeline on a system that is already up to date, temporarily enable reporting when no updates are available:

bash
# Enable "no updates" notifications for testing
sudo sed -i 's/^emit_no_updates = no$/emit_no_updates = yes/' /etc/dnf/automatic.conf

# Run the test
sudo dnf5 automatic

# Disable "no updates" notifications (restore default)
sudo sed -i 's/^emit_no_updates = yes$/emit_no_updates = no/' /etc/dnf/automatic.conf

Troubleshooting

SymptomLikely Cause
Config file not found: /root/.dnf-mail-apiThe credentials file was not created or is in the wrong location.
permissions are 0o644, expected 0o600Run sudo chmod 600 /root/.dnf-mail-api to fix permissions.
[graph] missing required key: ...A required field is blank or missing in the credentials file.
Failed to obtain Graph tokenCheck tenant_id, client_id, and client_secret values. Verify the App Registration has Mail.Send permission with admin consent.
boto3 is not installedRun sudo dnf install -y python3-boto3.
SES send_email failedVerify IAM credentials, region, and that the sender address is verified in SES.
Script runs but no email arrivesConfirm email_to contains the correct recipient address(es). Check spam folders.