docker icon indicating copy to clipboard operation
docker copied to clipboard

Allow setting admin user email via environment variable during initial setup

Open marscat5 opened this issue 8 months ago • 2 comments

After a fresh Docker-based install with all SMTP settings supplied via environment variables, the send test via "Basic settings → Test and verify email settings" result in the following error: AxiosError: Request failed with status code 400 This error message is not helpful and gives no indication of the root cause. It took me several days of debugging - including repeatedly verifying and adjusting the SMTP settings - before I realized that the problem was simply that the admin user had no email address set.

Expected Behavior

A fresh installation should allow specifying an admin email during setup. Without it, the email system silently fails with unclear error messages, despite all SMTP settings appearing correct.

Proposed Solution

Introduce a new environment variable, such as NEXTCLOUD_ADMIN_EMAIL, which can be used during container initialization to automatically assign an email address to the admin user.

environment:
  - NEXTCLOUD_ADMIN_USER=admin
  - NEXTCLOUD_ADMIN_PASSWORD=secret
  - [email protected]

Benefits

  • Prevents misleading errors like AxiosError: Request failed with status code 400 when testing email
  • Reduces time wasted on debugging SMTP configs
  • Streamlined, fully automated deployment
  • Enables functional email notifications from the start
  • Avoids manual post-installation steps

This would align well with the goals of containerization and automation. Thanks for considering!

marscat5 avatar May 04 '25 20:05 marscat5

Hello @marscat5.

I think this issue its not a bug because you can do this task specifying a post-install script to attach an email addres to admin account. And i think mainteners won't change entrypoint in order to keep it clean. xD

Follow this steps:

  1. In your compose, define the volume: - ./app-hooks/post-installation:/docker-entrypoint-hooks.d/post-installation
  2. Create the folder structure: mkdir -p ./app-hooks/post-installation
  3. Create script inside the subdirectory: touch ./app-hooks/post-installation/add-admin-email.sh
  4. Mark as executable: chmod +x ./app-hooks/post-installation/add-admin-email.sh
  5. Add this script to add-admin-email.sh with your favorite editor:
#!/bin/bash

if [ -n "${NEXTCLOUD_ADMIN_EMAIL+x}" ] && [ -n "${NEXTCLOUD_ADMIN_USER+x}" ]; then
    echo "Setting admin user email to: $NEXTCLOUD_ADMIN_EMAIL"
       
    php occ user:setting "$NEXTCLOUD_ADMIN_USER" settings email "$NEXTCLOUD_ADMIN_EMAIL"
    
    if [ $? -eq 0 ]; then
        echo "Admin email set successfully"
    else
        echo "Failed to set admin email"
    fi
else
    echo "NEXTCLOUD_ADMIN_EMAIL not set, skipping admin email configuration"
fi

Don't forget to set NEXTCLOUD_ADMIN_EMAIL in your environment.

Could you test and provide some feedback? Thanks.

Hope it helps.

henmohr avatar Jul 04 '25 12:07 henmohr

The approach from @henmohr should work (and is a great example of how many of the requests for customization are accommodated within the existing hooks framework - which perhaps could use some more examples #2231).

That said, I like the idea of adding NEXTCLOUD_ADMIN_EMAIL to the base entrypoint myself.

joshtrichards avatar Jul 04 '25 13:07 joshtrichards