docker icon indicating copy to clipboard operation
docker copied to clipboard

Clarify options for SMTP environment variables

Open alexpovel opened this issue 5 years ago • 2 comments

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 to ssl to use SSL, or tls to use STARTTLS.
  • SMTP_PORT (default: 465 for SSL and 25 for non-secure connections): Optional port for the SMTP connection. Use 587 for an alternative port for STARTTLS.
  • SMTP_AUTHTYPE (default: LOGIN): The method used for authentication. Use PLAIN if 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_PORT is the only option that can be left out. It clearly states optional, but this could be pronounced even more, maybe:

    SMTP_PORT (Optional; default: 465 for SSL and 25 for non-secure connections): Port for the SMTP connection. Use 587 for an alternative port for STARTTLS.

  • MAIL_FROM_ADDRESS sounds 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 the From field intuitively. However, it seems only the X part is meant here. In the email docs example, we would have MAIL_FROM_ADDRESS=noreply:

    email_config

  • The MAIL_DOMAIN is, following the above example, the Y.Z part. 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:

image

as hoped.

I can submit a PR clarifying the README, if desired.

alexpovel avatar Jul 22 '20 14:07 alexpovel

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')) {

dza89 avatar Oct 18 '20 14:10 dza89

@alexpovel thanks this just helped me to sort out why my mail client was not working. +1 for this 👍

ozboss avatar Oct 22 '20 21:10 ozboss

Fixed in #2144 & #1929

joshtrichards avatar Jun 21 '24 18:06 joshtrichards