Troubleshooting email on a new Discourse install

19 posts were split to a new topic: Cannot get email working on new install

Easier than opening a ticket is using port 2525. I use it by default on my installs and never have a problem.

5 Likes

4 posts were split to a new topic: Can send email from command-line but not Discourse

It might be useful to add to the guide that a normal log for a sent message looks like this

Sent mail to ****@gmail.com (413.2ms) Rendering text template Rendered text template (0.0ms) Completed 200 OK in 576ms (Views: 0.9ms | ActiveRecord: 16.2ms)

… and If you still do not receive mail, check the “skipped” tab of admin-email settings, i.e /admin/email/skipped

In my case, AWS-SES was rejecting messages because my “reply by email” address was incorrect, which was apparent from the error message found on the skipped tab. There is a catch, however. Failed test messages do not show up in skipped. I was only able to see the error message because there were attempts to send digests that also failed for the same reason. I could find no record of the test message fails in /admin/email/. Maybe this is a bug.

Finally, when I finally do get the test message I get some helpful hints that I can only read after the problem is fixed. That template text should be in this guide, not a message you cannot read until you have found the fix.

2 Likes

In case it helps anyone here, this was the solve for an installation unable to get emails to deliver.
They wanted to use their CPanel server for outgoing mail and it just wasn’t working.

Cpanel gives you details like this:

Which led to an app.yml like this:

DISCOURSE_SMTP_ADDRESS: example.com
DISCOURSE_SMTP_PORT: 465
DISCOURSE_SMTP_USER_NAME: me@example.com
DISCOURSE_SMTP_PASSWORD: password

way too much hacking later and I got that working by doing this in the rails console.

Discourse::Application.config.action_mailer.smtp_settings[:tls]=true

:bulb: :blush: ok, so now I actually read up on the fun that is STARTTLS

The correct configuration is to use the scary looking NOT Recommended outgoing port of 587 (yes, the discourse default) and let STARTTLS do it’s thing.

Also, people often don’t know how to setup SSL on their shared cpanel servers for mail so you will likely experience certificate warnings which will also stop this from working.

Final settings needed:

DISCOURSE_SMTP_ADDRESS: example.com
#DISCOURSE_SMTP_PORT:                    # (optional, default 587)
DISCOURSE_SMTP_USER_NAME: me@example.com
DISCOURSE_SMTP_PASSWORD: password
#DISCOURSE_SMTP_ENABLE_START_TLS:         # (optional, default true)
DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none

Seems obvious but there was nothing in the logs that helped identify the reason for the problem other than it just doesn’t work.

5 Likes

thank you, this does the job.
I spend hours and hours with my own email server configured with TLS only on port 587.
struggling, no helpful log.
Finally, I added this parameter and it works :sunny:

By the way, rebuilding app takes so long, just for a small change of parameter value.
I wish it may exist a simpler way, without forcing rebuilding all but taking account of changes in settings : containers/app.yml

For a quick way to try different parameter without having to rebuild the app:

If you look at /var/discourse/shared/standalone/log/var-log, there are several files with a .txt suffix.
(for example, on my system I have MDJlYzAyNzY5NzcxOWY2.txt and a couple more)

If you grep /usr/bin/docker * in that directory you can see how the container is started.For me the command showed up in one of these .txt file (although I seem to remember seeing it in the syslog file the first I went looking for it.
Note that most of the parameters come directly from the containers/app.yml file.

I grabbed the command line and put it in a file. I can edit it, and start a container with different parameters to try things out (port mapping, hostname, SMTP parameters…)

That seems to work as long as you only change variables that are passed as arguments there.

For this to work, you need to stop the container if it is already running, and remove it. By default the container is called app.

docker stop app
docker rm app

Here’s what the command looks like for me (sensitive info replaced with xxx)
I saved it to a file I called start_container.sh and made the file executable (and added the stop and rm commands so I don’t forget)

#!/bin/bash
/usr/bin/docker stop app
/usr/bin/docker rm app
/usr/bin/docker run --shm-size=512m -d --restart=always -e LANG=en_US.UTF-8 -e RAILS_ENV=production -e UNICORN_WORKERS=4 -e UNICORN_SIDEKIQS=1 -e RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 -e RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000 -e RUBY_GC_HEAP_INIT_SLOTS=400000 -e RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.5 -e DISCOURSE_DB_SOCKET=/var/run/postgresql -e DISCOURSE_DB_HOST= -e DISCOURSE_DB_PORT= -e DISCOURSE_HOSTNAME=xx.xx.xx -e DISCOURSE_DEVELOPER_EMAILS=xx@xx.xx.xx -e DISCOURSE_SMTP_ADDRESS=in-v3.mailjet.com -e DISCOURSE_SMTP_PORT=587 -e DISCOURSE_SMTP_USER_NAME=xxx -e DISCOURSE_SMTP_PASSWORD=xxxxx -e DISCOURSE_SMTP_ENABLE_START_TLS=true -h lrose-app -e DOCKER_HOST_IP=172.17.0.1 --name app -t -p 8888:80 -p 443:443 -v /var/discourse/shared/standalone:/shared -v /var/discourse/shared/standalone/log/var-log:/var/log --mac-address xxxxx local_discourse/app /sbin/boot
1 Like

For a quicker way, try:

./launcher destroy app
./launcher start app
4 Likes

I had properly the same problem

tail -f /var/discourse/shared/standalone/log/rails/production.log
Sent mail to user@mail.com (61113.9ms)
Job exception: Net::ReadTimeout

mentioned in


and here

as solution is on

maybe 465 works but there is a bug as described on


so verify username and password that they don’t begin with “Q” or “R”, using https://www.base64encode.net/

5 posts were split to a new topic: Can’t get Siteground Email and one-click droplet to work

Hello,

I am trying your solution but no success :frowning:
I have created the mail account (and also the discourse install) in a subdomain.

so it looks something like

DISCOURSE_SMTP_ADDRESS: subdomain.example.com
DISCOURSE_SMTP_PORT: 465
DISCOURSE_SMTP_USER_NAME: discourse@subdomain.example.com
DISCOURSE_SMTP_PASSWORD: password

I have changed the app.yml to the final settings you have supplied (commenting out the smtp_port anddiscourse_smtp_enable_start_tls and adding discourse_smtp_openssl_verify_mode:none.

But now I don’t know what do do.
the discourse-doctor says the email is sent but I never receive it. I have used mail-tester.com and they too say it’s never received. But I don’t know what I have to change in Cpanel or (where do I need to change it??) to let it send my mail.

can anyone help?

At the bottom of app.yml is a commented out line that lets you set the notification address. You likely need to change it to whatever your mark server is configured for. You could check the mail server logs to see the error.

thank you @pfaffman :slight_smile:
to answer my own question (and maybe help others), problem was with the ‘no-reply’ email address that didn’t exist as a sender, and the server blocking those. I created a no-reply account and that fixed it.

3 Likes

With more shared/standalone/log/rails/production.log, I got to know the connection is getting refused to my admin mail address admin@mydomain.com. But that mail address is working absolutely fine because it is receiving mails from other mail clients while in Discourse installation even I am not receiving an activation mail. Also, my cloud server on DigitalOcean is getting through the email server with this telnet mail.mydomain.com 465 but why the telnet connection with forums.mydomain.com is not getting established?
I am using CPanel by the way. Kindly assist!!

Looks like your digitalocean account is currently under probation and they’re blocking SMTP ports (25,254,587). To solve this, you can either configure your SMTP to listen to a non-standard port (e.g. 2525) and then update this in discourse so that it uses the new port for email transport.

4 Likes

There is no option to modify SMTP ports in my CPanel. Anyway, my gmail account is working. Is it advisable to use gmail as admin account with mail SMTP server from mailgun?

You can use any email address as admin account as long as it is a valid email address able to receive emails.

On mailgun SMTP, use port 2525 instead of 587 and you should be good to go.

1 Like

If you think that your mail configuration is fully ok, and yet your mails aren’t delivering. You can segregate the fault by trying to send mails thru your smtp server, but without the intervention of discourse. You just need access to your droplet thru a terminal.

I was able to send mails thru Terminal in the below given way. SSH to your droplet and go ahead as told below.

  • telnet smtp.mailgun.org 25
  • If ready msg comes, then: ehlo smtp.*****.com (replacing stars with your own smtp server name)
  • 6-7 msgs should come up containing 250 code.
  • auth login (you should get 334 VXNlcm5hbWU6 )
  • base64 encoded id: cd9zewhateveryouridisnUueHl6 (if your user id is ok, you should get 334 some-code).
  • base64 encoded pw: OnU2Njk7NWE1yourownpasswordherejllMzg= (you should get 235 2.0.0 ok msg)
  • mail from: <anyname@yoursendingdomainname> (you should get ‘250 sender address accepted’ msg)
  • rcpt to: <recipientname@gmail.com> (you should get ‘250 recipient address accepted’ msg)
  • data (you should receive ‘354 continue’ msg)
  • And now type your msg, whatever. And in the end just a period plus enter. At this, you should get ‘250 Great Success’ msg).

To come out, you can ‘quit’ or press ‘escape character+enter+quit’. You should get ‘221 See you later. Connection closed by foreign host’ msg).

What are the correct settings passed to ./discourse-setup for connecting to an smtp server on localhost:25 without auth?

I’m very surprised that this isn’t supported OOTB; it’s the default config on most linux installs…

My server runs postfix locally; it is not accessible from the Internet. It works fine, for example, when running the mail command. I found a few unofficial guides on the Internet suggesting changes to /var/discourse/containers/app.yml, and I finally got it to install & start with the following settings:

  DISCOURSE_SMTP_ADDRESS: localhost
  DISCOURSE_SMTP_PORT: 25
  DISCOURSE_SMTP_USER_NAME: discourse@opensouceecology.org
  DISCOURSE_SMTP_PASSWORD: "none"
  DISCOURSE_SMTP_AUTHENTICATION: none
  DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none
  DISCOURSE_SMTP_ENABLE_START_TLS: false

Note that if I omit the DISCOURSE_SMTP_USER_NAME or DISCOURSE_SMTP_PASSWORD variables, your install script yells at me stating that they’re required (bug?).

And now when I click the “Resend Activation Email” button in the Discourse wui, this entry pops-up in the log file (/var/discourse/shared/standalone/log/rails/production.log):

Started PUT "/finish-installation/resend-email" for 127.0.0.1 at 2019-11-07 13:15:31 +0000
Processing by FinishInstallationController#resend_email as HTML
  Parameters: {"authenticity_token"=>"SzQCvRWiqdXsBKzOjIB0X7KkvXro7Od6SdP8Qa8vvrskPeNYZNos5ORHJfyDUrHiKShZR/txM6NHuqHHCQCR1w=="}
  Rendering finish_installation/resend_email.html.erb within layouts/finish_installation
  Rendered finish_installation/resend_email.html.erb within layouts/finish_installation (Duration: 0.7ms | Allocations: 103)
  Rendered layouts/_head.html.erb (Duration: 0.5ms | Allocations: 103)
Completed 200 OK in 98ms (Views: 3.0ms | ActiveRecord: 0.0ms | Allocations: 4763)
  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.5ms | Allocations: 141)
Delivered mail c4ca58ca-345e-46c4-81bc-6d0eac7afa04@discourse.opensourceecology.org (11.3ms)
Job exception: wrong authentication type none

…But my authentication type is ‘none’. What should the correct setting be for no authentication?

EDIT: also, can someone link me to the doc that defines all of the possible “DISCOURSE_SMTP_*” variables and all of their valid values?

EDIT2: this is proving to be far more difficult than it should be. I think ‘localhost’ is resolving inside the docker container to the Discourse docker container itself (app) – not the docker host that is running my postfix smtp server. That’s further complicated by postfix’s mynetworks and iptables (which were configured by the discourse-setup script or its children scripts). What’s the correct config here to just have Discourse use the smtp server on which I want to run Discourse, with no smtp auth?

I think that hasn’t been very true for about 20 years.

You can’t use discourse-setup for situations like yours because few people have non password protected smtp servers, even behind a firewall.

What I would do is configure smtp passwords for my mail server. There really isn’t much downside.

If you don’t want to do that I think that instead of “none” for authentication you might want “” (and similarly for the password and username).

I think so too. You might try using the container name. I think that you need to see that they are both on the same docker network.

2 Likes