Clarify options for SMTP environment variables
I am not aware of a template for issues, so this is free-form!
In the README, it currently states:
To use an external SMTP server, you have to provide the connection details. To configure Nextcloud to use SMTP add:
SMTP_HOST(not set by default): The hostname of the SMTP server.SMTP_SECURE(empty by default): Set tosslto use SSL, ortlsto use STARTTLS.SMTP_PORT(default:465for SSL and25for non-secure connections): Optional port for the SMTP connection. Use587for an alternative port for STARTTLS.SMTP_AUTHTYPE(default:LOGIN): The method used for authentication. UsePLAINif no authentication is required.SMTP_NAME(empty by default): The username for the authentication.SMTP_PASSWORD(empty by default): The password for the authentication.MAIL_FROM_ADDRESS(not set by default): Use this address for the 'from' field in the emails sent by Nextcloud.MAIL_DOMAIN(not set by default): Set a different domain for the emails than the domain where Nextcloud is installed.
This makes for a total of 8 environment variables usable to configure SMTP on nextcloud. Some options are confusing and could be cleared up:
-
It appears
SMTP_PORTis the only option that can be left out. It clearly states optional, but this could be pronounced even more, maybe:SMTP_PORT(Optional; default:465for SSL and25for non-secure connections): Port for the SMTP connection. Use587for an alternative port for STARTTLS. -
MAIL_FROM_ADDRESSsounds like it requires a full email address, in the shape of[email protected]. This is how I had it at first and how I understand theFromfield intuitively. However, it seems only theXpart is meant here. In the email docs example, we would haveMAIL_FROM_ADDRESS=noreply:
-
The
MAIL_DOMAINis, following the above example, theY.Zpart. However, the 'different' part makes it sound optional. This is why I did not specify it at first, because I did not want a different domain. -
It is unclear to me what the difference between empty by default and not set by default is.
-
Debugging this wasn't the easiest, because it seems that unless all fields (save for
SMTP_PORT) are specified, no entries are saved and the fields in the above image remain blank. This is even though all other entries/environment variables are present/correct.
I tested with this smtp.env:
SMTP_HOST=smtp.example.com
SMTP_SECURE=ssl
SMTP_AUTHTYPE=PLAIN
[email protected]
SMTP_PASSWORD=secret
MAIL_FROM_ADDRESS=info
MAIL_DOMAIN=cloud.example.com
then running
docker run --rm -p 8080:80 --env-file smtp.env nextcloud
in the same directory. This yields:

as hoped.
I can submit a PR clarifying the README, if desired.
The MAIL_DOMAIN is indeed mandatory, which is not cleary stated in the docs. I would also not expect it to be mandatory tbh.
if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) {
@alexpovel thanks this just helped me to sort out why my mail client was not working. +1 for this 👍
Fixed in #2144 & #1929