# Cannot send email - problem with port 465

**URL:** https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004
**Category:** Self-hosting
**Tags:** email
**Created:** [November 18, 2022, 4:11am UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004 "2022-11-18T04:11:29Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [November 18, 2022, 4:11am UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/1 "2022-11-18T04:11:29Z")

</div>

I would like to change the SMTP provider, but it doesn’t seem to work although I’m certain that the server can send emails.

I have this in `app.yml`:

```yml
  DISCOURSE_SMTP_ADDRESS: <<SMTP SERVER>>
  DISCOURSE_SMTP_PORT: 465
  DISCOURSE_SMTP_USER_NAME: <<USER>>
  DISCOURSE_SMTP_PASSWORD: <<PASSWORD>>

```

Using `telnet <<SMTP SERVER>> 465` connects OK, but when I try to send emails, Discourse returns with:

```plaintext
ERROR - Net::ReadTimeout with #<Socket:(closed)> 

```

Anybody has any pointers to what I need to set?

I checked out the server based on this topic: [Troubleshoot email on a new Discourse install](https://meta.discourse.org/t/troubleshoot-email-on-a-new-discourse-install/16326)

It appears to connect to the server and send a test email correctly if I do that manually:

```plaintext
> sudo ./launcher enter app
root@support-app:/var/www/discourse# openssl s_client -connect mail.xxxxxxxx.com:465
  :
  :
  massive amount of junk
  :
  :
220 xxxxxxx.com Anti-spam GT for Coremail System (mispb-6da2110f-64b0-4d67-acf1-2d302bd594f9-xxxxxxx.com[20220915])
EHLO mail.xxxxxxxxx.com
250-mail
250-PIPELINING
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-coremail 1Uxr2xKj7kG0xkI17xGrUDI0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UrpDiNKUCa0xDrUUUUj
250-STARTTLS
250-SMTPUTF8
250 8BITMIME
AUTH PLAIN xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
235 Authentication successful
mail from: <xxx@xxxxxx.com>
250 Mail OK
rcpt to: <xxxx@xxxxxxx.com>
250 Mail OK
data
354 End data with <CR><LF>.<CR><LF>
content

.
250 Mail OK queued as AQAAfwBXr9nSGHdj3hEgAA--.7073S2

```

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [November 18, 2022, 7:13am UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/2 "2022-11-18T07:13:54Z")

</div>

> [@schungx](#):
>
> It appears to connect to the server and send a test email correctly if I do that manually:

How long does it take for the output to appear?

> [@SMTP Net::ReadTimeout without relation to net or login problems - SMTP host is just slow](https://meta.discourse.org/t/smtp-net-readtimeout-without-relation-to-net-or-login-problems-smtp-host-is-just-slow/235727):
>
> Hello, since view weeks sending mail from my Discourse instance fails. The SMTP settings are unchanged, curl test is still working but notably slow. The smtp server from our hoster (that we need to send mails with) has a consistent send time of 7 seconds. cat testmail | curl -vvv --url 'smtp://smtp.\<HOST\>:587' --mail-from mail@\<DOMAIN\> --mail-rcpt \<ME\> --user "mail@\<DOMAIN\>:\<PW\>" -T - % Total % Received % Xferd Average Speed Time Time Time Current …

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [November 18, 2022, 7:18am UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/3 "2022-11-18T07:18:10Z")

</div>

> [@RGJ](#):
>
> How long does it take for the output to appear?

Quite immediately after I send a command.

EDIT: Is there a way to get more detailed logging to discover which step is causing the error?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [November 18, 2022, 10:19pm UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/4 "2022-11-18T22:19:47Z")

</div>

It’s likely that the outgoing port is being blocked by your hosting provider. If you’re using some service like mailgun (or most any other) then port 2525 should work. If it’s a mail server you run, then you can have it listen to another port (like 2525).

Or (probably hardest) you can open a ticket with whoever hosts your server and ask them to open the port.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [November 19, 2022, 2:35am UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/5 "2022-11-19T02:35:10Z")

</div>

Well, considering I can `./launcher enter app` and then `openssl` connect to the mail server, login via SMTP and successfully sent an email from within the discourse container, I doubt that it is the port that doesn’t work…

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [November 19, 2022, 5:12am UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/6 "2022-11-19T05:12:20Z")

</div>

I traced the code and it seems that `EHLO` wasn’t even reached. The SMTP server is connected but the SSL handshake seems to be missing, so the server quits and Discourse didn’t get any response, thus the error.

So, I suspected that **port 465** support seems to have a bug (it defaults to SSL, but I don’t think Discourse recognizes that) so probably the SSL connection is never established.

Switching to port 25 seems to at least get rid of the error, although I am not receiving any sent email yet…

EDIT: I can confirm that port 25 works properly (as should 587 but unfortunately my smtp server doesn’t expose 587).

I didn’t get any emails before was due to the fact that the Discourse server IP address was temporarily blacklisted by the smtp server because of too many failed attempts.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [November 19, 2022, 8:59am UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/7 "2022-11-19T08:59:34Z")

</div>

I think you’re right.

And it turns out you’re not the first… when searching for `DISCOURSE_SMTP_PORT 465` I found a whole pile of similar issues.

- [Not able to send email Net::ReadTimeout - #18 by Stranik](https://meta.discourse.org/t/not-able-to-send-email-net-readtimeout/98419/18)
- [Email not working but i can access smtp server from container](https://meta.discourse.org/t/email-not-working-but-i-can-access-smtp-server-from-container/168132)
- [DigitalOcean + Siteground Email via port 465 won’t work (2525 will work)](https://meta.discourse.org/t/digitalocean-siteground-email-via-port-465-won-t-work-2525-will-work/125067)
- [Problem with SMTP configuration](https://meta.discourse.org/t/problem-with-smtp-configuration/65892)
- [Post-install, Curl can send email, but Discourse cannot. Help to fix?](https://meta.discourse.org/t/post-install-curl-can-send-email-but-discourse-cannot-help-to-fix/159900)
- [Mail problem on discourse with reverse proxy](https://meta.discourse.org/t/mail-problem-on-discourse-with-reverse-proxy/217563)
- [Can't setup SMTP with SSL/TLS](https://meta.discourse.org/t/cant-setup-smtp-with-ssl-tls/190104)
- [SMTP email issue Net::Timeout - #3 by neounix](https://meta.discourse.org/t/smtp-email-issue-net-timeout/180080/3)

The last one contains [a link to the (possible?) solution](https://github.com/discourse/discourse/commit/9aeece465f222aa291891d8590ae3660097de37a).

```plaintext
With this patch, it's possible to set
DISCOURSE_SMTP_FORCE_TLS=true to use implicit TLS on port 465

```

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [November 19, 2022, 9:31am UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/8 "2022-11-19T09:31:05Z")

</div>

I’ve also seen quite a few ‘465 problem’ topics too. My email debugging for anything but the obvious is not great though so I have been quoting the troubleshooting guide:

> [@Troubleshoot email on a new Discourse install](https://meta.discourse.org/t/troubleshoot-email-on-a-new-discourse-install/16326/1):
>
> ## Email smtp port selection (Using 465?)
> 
> The ability to be able to [AUTH using ‘telnet’](https://meta.discourse.org/t/troubleshooting-email-on-a-new-discourse-install/16326/114) is extremely important in your first steps of email troubleshooting.
> 
> Port 465 (SMTP over SSL) is largely deprecated in favor of STARTTLS on 25. You may need to try alternate ports such as [port 2525](https://pepipost.com/blog/25-465-587-2525-choose-the-right-smtp-port/) or port 587 (Mail Submission) when things do not seem to work as expected.

Is there something we can add to that to help people?

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [November 19, 2022, 10:21am UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/9 "2022-11-19T10:21:59Z")

</div>

> [@JammyDodger](#):
>
> Is there something we can add to that to help people?

Well, if @schungx is able to confirm that `DISCOURSE_SMTP_FORCE_TLS=true` is indeed a solution, we can add that.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [November 20, 2022, 4:37am UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/10 "2022-11-20T04:37:07Z")

</div>

> [@RGJ](#):
>
> Well, if @schungx is able to confirm that `DISCOURSE_SMTP_FORCE_TLS=true` is indeed a solution, we can add that.

I’ll try right away!

EDIT: @RGJ I can confirm that `DISCOURSE_SMTP_FORCE_TLS: true` in `app.yml` successful solves the problem! 🍾

I suggest a bold warning saying **If you use port 465, set `DISCOURSE_SMTP_FORCE_TLS: true`** , or shouldn’t Discourse be smart enough to detect this?

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 20, 2022, 4:37am UTC](https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/11 "2022-12-20T04:37:56Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
