Allow setting admin user email via environment variable during initial setup
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 400when 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!
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:
- In your compose, define the volume:
- ./app-hooks/post-installation:/docker-entrypoint-hooks.d/post-installation - Create the folder structure:
mkdir -p ./app-hooks/post-installation - Create script inside the subdirectory:
touch ./app-hooks/post-installation/add-admin-email.sh - Mark as executable:
chmod +x ./app-hooks/post-installation/add-admin-email.sh - Add this script to
add-admin-email.shwith 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.
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.