User sandybeauty reported an issue where Discourse failed to send emails via Sparkpost, throwing a “500 5.5.2 unrecognized command” error, despite successful tests using CURL. After pfaffman suggested uncommenting the SMTP port setting in the configuration, sandybeauty confirmed the problem was resolved. This led to a discussion regarding whether the default port behavior was a bug. pfaffman noted that while standalone.yml implies a default port of 587 with TLS, this did not match the observed behavior. codinghorror explained the complexities of SMTP ports, noting that port 587 typically requires STARTTLS, while port 465 uses implicit SSL, and that practices vary across providers. DeanMarkTaylor and pfaffman pointed to source code suggesting the default might be port 25 and highlighted missing port configuration in setup scripts. In response, codinghorror clarified that TLS can function on any port and announced a fix: the ./discourse-setup script was updated to make the SMTP port explicitly selectable, defaulting to 587. This ensures the app.yml file explicitly specifies the port rather than relying on implicit defaults, preventing similar issues for future users.
DISCOURSE_SMTP_ADDRESS: smtp.sparkpostmail.com
#DISCOURSE_SMTP_PORT: 587 # (optional, default 587)
DISCOURSE_SMTP_USER_NAME: SMTP_Injection
DISCOURSE_SMTP_PASSWORD: API keys( working with curl test)
## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
#LETSENCRYPT_ACCOUNT_EMAIL: me@example.com
- exec: rails r "SiteSetting.notification_email='noreply@myownweb.com'"
SMTP uses port 25, but SSL/TLS encrypted SMTP uses port 465.
Many sites now disable plain IMAP (port 143) and plain POP (port 110) altogether so people must use an SSL/TLS encrypted connection. By disabling ports 143 and 110, this removes completely STARTTLS as even an option for IMAP/POP connections.
The one real exception to the above is SMTP. However that’s for a different reason again. Most email software used SMTP on port 25 to submit messages to the email server for onward transmission to the destination. However, SMTP was originally designed for transfer, not submission. So yet another port (587) was defined for message submission. Although port 587 doesn’t mandate requiring STARTTLS, the use of port 587 became popular around the same time as the realisation that SSL/TLS encryption of communications between clients and servers was an important security and privacy issue.
The result is that in most cases, systems that offer message submission over port 587 require clients to use STARTLS to upgrade the connection and also require a username and password to authenticate.
Currently, things seem relatively randomly split between people using SMTP SSL/TLS encrypted over port 465, and people using SMTP with STARTTLS upgrading over port 587.
I went ahead and made the port selectable in the ./discourse-setup script, with a value of 587 as the default that gets written to the app.yml file. That way we are no longer relying on implicit defaults, the app.yml will have the actual SMTP port specified.
(For the record, I’ve used the default – that is, leaving that line commented out – with mailgun and mandrill for ages and never had issues. But I think it’s best to be explicit here.)