# Failing to connect to SMTP mail server

**URL:** https://meta.discourse.org/t/failing-to-connect-to-smtp-mail-server/112737
**Category:** Self-hosting
**Created:** [3월 27, 2019, 5:53오후 UTC](https://meta.discourse.org/t/failing-to-connect-to-smtp-mail-server/112737 "2019-03-27T17:53:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Eisfunke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eisfunke/32/135343_2.png) [@Eisfunke](https://meta.discourse.org/u/Eisfunke)
#### Post date: [3월 27, 2019, 5:53오후 UTC](https://meta.discourse.org/t/failing-to-connect-to-smtp-mail-server/112737/1 "2019-03-27T17:53:09Z")

</div>

Hi everybody,

I’m having trouble configuring my mail server on Discourse.

I’m running my own SMTP server with OpenSMTPD. It works, I’m using it successfully with my Gitea and my Nextcloud.

Discourse doesn’t seem to like it though. When I try to register my admin account I don’t receive the confirmation mail.

The log in `shared/standalone/log/rails/production.log` says for each mail:

```plaintext
Sent mail to [my mail address] (64.9ms)
Job exception: Cannot assign requested address - connect(2) for "[my mail server]" port 587

```

My mail server never gets any connections according to its logs.

These are the mail settings from my `app.yml`:

```plaintext
DISCOURSE_SMTP_ADDRESS: [my mail server]
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: [my mail server user]
DISCOURSE_SMTP_PASSWORD: "[my password]"
#DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)

```

Again, the exact same settings (same user, same address, same password, same port, also STARTTLS) are working in my Gitea and my Nextcloud without problems.

I already tried:

- Putting the password in single quotes instead of double quotes
- Setting TLS to false
- Setting a custom from-mail at the end of `app.yml` (though this probably isn’t the problem as my NC/Gitea use `noreply@subdomain.domain.tld` as addresses just like Discourse does and it works)
- Searching for the error message in the Discourse log, but I didn’t find anything.
- For the record, I ran `launcher rebuild app` after each change.
- `telnet [my mail server]` connects just fine.

I’m running Discourse on my home server, the SMTP server is on my VPS (both run Arch Linux).

Anybody have any ideas what could be going wrong?

---

<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: [3월 27, 2019, 7:48오후 UTC](https://meta.discourse.org/t/failing-to-connect-to-smtp-mail-server/112737/2 "2019-03-27T19:48:57Z")

</div>

It looks like discourse can’t connect to your mail server.

Can you `telnet my-mail-server 587` from the server? From inside the container?

You can see if `./discourse-doctor` gives you any clues.

---

<div class="post-metadata">

### Author: ![Eisfunke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eisfunke/32/135343_2.png) [@Eisfunke](https://meta.discourse.org/u/Eisfunke)
#### Post date: [3월 27, 2019, 8:30오후 UTC](https://meta.discourse.org/t/failing-to-connect-to-smtp-mail-server/112737/3 "2019-03-27T20:30:42Z")

</div>

Telnetting from _inside_ the container and `discourse-doctor` both failed with the exact same message.

It brought me onto the right track though. I tried out `telnet` from some other machines and stumbled upon the problem with one with IPv6 disabled: My mail server didn’t accept IPv4 connections.  
Nextcloud and Gitea on the same machine were fine using IPv6, but Discourse seemingly doesn’t (maybe a Docker limitation?).

Anyway: I fixed the mail server config and it works flawlessly now. Thanks for the help! 😄

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [4월 1, 2019, 12:03오후 UTC](https://meta.discourse.org/t/failing-to-connect-to-smtp-mail-server/112737/4 "2019-04-01T12:03:59Z")

</div>


