Cannot receive the mail from email server

AI-generated summary

Cannot receive the mail from email server

The user, chiehpower, is experiencing issues with receiving emails from their email server on a Discourse installation. They followed the installation guide and initially had success with sending emails using localhost as the DISCOURSE_HOSTNAME. However, when they changed the DISCOURSE_HOSTNAME to their internal IP address (10.1.3.91), they encountered issues with sending emails.

In their second post, chiehpower updated the discussion, stating that they initially received emails with the internal IP address but later encountered an error where the page could not be found.

chiehpower eventually solved the problem by editing the /etc/hosts file to set the hostname to their IP address. They found that using the internal IP address as the DISCOURSE_HOSTNAME worked for internal use.

Dear all,

I knew this issue which is a known issue and quite easily to meet it. I have read and tried a lot of testings, but I already got stuck on “sending email” this step.

I was following this discourse/docs/INSTALL-cloud.md at main · discourse/discourse · GitHub that here are my steps below.

git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse

Go to /samples/ to copy standalone.yml to /containers/app.yml

Please amend the information about your server.
Next,

sudo ./discourse-doctor

First experiment

When my app.yml was set

DISCOURSE_HOSTNAME : 'localhost'

And fill up these information

  DISCOURSE_SMTP_ADDRESS: XXX
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: XXX
  DISCOURSE_SMTP_PASSWORD: XXX
  DISCOURSE_SMTP_ENABLE_START_TLS: true   

The email server is also built on internal network.
In the beginning, it can work. The discourse can correctly send the register email and I can also access the admin like normal.

However, when I set the localhost of HOSTNAME, I cannot use the internal IP (e.g., 10.1.X.X) to access on browser.


Second experiment

So I only amended my DISCOURSE_HOSTNAME and I didn’t modify other information in app.yml.

DISCOURSE_HOSTNAME : '10.1.3.91'

PS 10.1.3.91 is my internal (local area) IP.

After I changed to this kind of hostname, I can access it on my browser. However, the email server cannot work anymore. I cannot receive the email from discoure.


Supplement

I tried to send the email via python with my SMTP.

The script is like below:

from email.mime.multipart import MIMEMultipart
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib

content = MIMEMultipart() 
content["subject"] = "Learn Code With Mike"  
content["from"] = " (my email) "  
content["to"] = " (testing email) "
content.attach(MIMEText("Demo python send email"))  


with smtplib.SMTP(host=" (as same as DISCOURSE_SMTP_ADDRESS) ", port="587") as smtp: 
    try:
        smtp.ehlo() 
        smtp.starttls()  
        smtp.login(" (as same as DISCOURSE_SMTP_USER_NAME) ", " (as same as DISCOURSE_SMTP_PASSWORD) ") 
        smtp.send_message(content)  
        print("Complete!")
    except Exception as e:
        print("Error message: ", e)

Then it can work well. Does it prove the email stmp information which is correct and be able to use?

Is there any idea about this issue?

For email server part, I have also tried the Elastic Email, Mailjet but still not work.

Conclusion:

If DISCOURSE_HOSTNAME is used localhost, email server can work.
If DISCOURSE_HOSTNAME is changed to internal IP (i.e., local area IP), email server cannot work.

Thank you so much!!!

Best regards,
Chieh

Update:

I can receive the email in the beginning of “congratulations, you installed Discourse!” and “register Admin Account” with the specific internal IP when I access on other device. However, after these steps, it will get error that it cannot find the page. Why is it originally able to access by internal IP and after this setting, the original IP will be invalid?
So strange …

The problem seems be solved by myself.

go to /etc/hosts

and set the hostname being your IP.
hostname is also set IP.

DISCOURSE_HOSTNAME can use internal IP.
Then it can work.

(Of course, it is only for internal use.)