500 5.5.1 Invalid command: Cannot send mail with Discourse on new install but can from command line (on digital ocean)

AI-generated summary

Users are troubleshooting an issue where Discourse fails to send emails with a “500 5.5.1 Invalid command” error on a new Digital Ocean install, despite SMTP working via command line and Python scripts. b4oshany uses Mailu as a custom SMTP server with StartTLS on port 587 and initially suspected the % in their password, though it was already quoted. itsbhanusharma suggested quoting the password, and Stephen recommended changing it — which b4oshany tried without success. Eventually, b4oshany resolved the issue by adjusting mail settings, though specifics weren’t shared. NightMachinary also got it working, crediting discourse-doctor for helping diagnose the problem. discoursekomrad seeks the fix, and b4oshany advises testing SMTP first using the Real Python guide linked here, which helped them isolate the issue. The consensus suggests verifying SMTP connectivity independently before configuring Discourse, and using discourse-doctor for debugging.

I’m getting the following error using ./discourse-docker on Digital Ocean after installation

==================== MAIL TEST ====================
For a robust test, get an address from http://www.mail-tester.com/
Or just send a test message to yourself.
Email address for mail test? ('n' to skip) [forum@jamaicans.dev]: 
Sending mail to forum@jamaicans.dev. . . 
Testing sending to forum@jamaicans.dev using mail.jamaicans.dev:587.
======================================== ERROR ========================================
                                    UNEXPECTED ERROR

500 5.5.1 Invalid command

is forum@jamaicans.dev a valid email Address?
Are you using a custom SMTP?

Yes, I’m running my own Mail server using Mailu → Mailu — Mailu, Docker based mail server.

I wrote a python script to test if it is send emails using the SMTP credentials, and I’m able to send and receive emails. I also tried Telnet, which works. The port is running on 587 with StartTLS. DMARC and SPF has already been setup.

The mail account has a % sign in the password. I noticed in the app.yaml that the passowrd shouldn’t have in a #. Do you think this would be the culprit?

Enclose the password in Quotes e.g. 'P@$$w0RD%100' that should make it work

It is already enclosed

Why not change the password and find out?

I did, waiting on the rebuild to complete… but just in case it fails, I wanted to find out if anyone else got this message

It didn’t work. I’ll probably just use mail gun

Can you share your Python script? I, too, installed mailu, and I like to test it.

Update: Nevermind, I created it myself via Sending Emails With Python – Real Python. Mailu works (without TLS, as I haven’t figured out how to use letsencrypt with both mailu and caddy), but discourse doesn’t send emails …

Hi,
It also worked for me. I made some changes to mail settings and it started to work. Sorry for not indicating that I got it to work.

I got it working, too. Testing it with discourse-doctor helped a lot.

I have the same error. Do either of you remember what you did to fix it?

Honestly, no, but try to get it working with example seen in real python first. I think this led me to the solution.