# Unable to send emails using local SMTP server

**URL:** https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643
**Category:** Self-hosting
**Created:** [January 20, 2021, 1:43am UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643 "2021-01-20T01:43:31Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![superman](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@superman](https://meta.discourse.org/u/superman)
#### Post date: [January 20, 2021, 1:43am UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/1 "2021-01-20T01:43:31Z")

</div>

I have tested the SMTP server with Telnet:  
Telnet connected to the SMTP server.  
Telnet allowed me to authenticate into the SMTP server.  
Telnet allowed me to successfully send an email using the SMTP server, and I used the exact same values in Telnet as are present in the /var/discourse/containers/app.yaml file.

Discourse doctor says that Discourse successfully connected to the SMTP server.  
Discourse doctor says that Discourse failed to send the test email.

Therefore, Discourse has bugs preventing it from sending emails.

---

<div class="post-metadata">

### Author: ![HAWK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hawk/32/86627_2.png) [@HAWK](https://meta.discourse.org/u/HAWK)
#### Post date: [January 20, 2021, 2:32am UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/2 "2021-01-20T02:32:45Z")

</div>

I’d suggest that it’s something about your setup that is broken, rather than bugs within Discourse. 😉

---

<div class="post-metadata">

### Author: ![Syonyk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/syonyk/32/206551_2.png) [@Syonyk](https://meta.discourse.org/u/Syonyk)
#### Post date: [January 20, 2021, 2:37am UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/3 "2021-01-20T02:37:51Z")

</div>

Are you by chance using [smtp-relay.gmail.com](http://smtp-relay.gmail.com), perhaps from DigitalOcean? That seems to have broken recently and nobody is quite sure why yet.

---

<div class="post-metadata">

### Author: ![superman](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@superman](https://meta.discourse.org/u/superman)
#### Post date: [January 20, 2021, 2:37am UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/4 "2021-01-20T02:37:58Z")

</div>

No. Because the SMTP server is working perfectly as already described and Discourse is properly installed and properly returns the screen that prompts the admin registration email. However, that email does not send.

---

<div class="post-metadata">

### Author: ![superman](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@superman](https://meta.discourse.org/u/superman)
#### Post date: [January 20, 2021, 2:44am UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/6 "2021-01-20T02:44:42Z")

</div>

I am using a local SMTP server located on the same machine as the Discourse Docker container.

---

<div class="post-metadata">

### Author: ![superman](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@superman](https://meta.discourse.org/u/superman)
#### Post date: [January 20, 2021, 3:33am UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/7 "2021-01-20T03:33:23Z")

</div>

I found an error in /var/discourse/shared/standalone/log/rails/production.log:

```
Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.1ms | Allocations: 32)
Delivered mail f915c15e-9c4d-4d4e-9527-81bc4984540c@forum.domain.com (63.7ms)
Job exception: hostname "mail.forum.domain.com" does not match the server certificate

```

What does this error mean?

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [January 20, 2021, 3:41am UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/8 "2021-01-20T03:41:33Z")

</div>

> [@Hostname does not match server certificate](https://meta.discourse.org/t/hostname-does-not-match-server-certificate/65350):
>
> Guys, I’ve tried all you have previously suggested but definitely I cannot succeed with that. Log says that the hostname does not match the server certificate. Any bit of help? Thanks for your time, it’s bit frustrating. Cheers!

---

<div class="post-metadata">

### Author: ![superman](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@superman](https://meta.discourse.org/u/superman)
#### Post date: [January 20, 2021, 1:05pm UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/9 "2021-01-20T13:05:59Z")

</div>

It appears the above error message is talking about the server ssl certificate.

The ssl certificate on the server is correct and has the proper hostname.

It looks as though this is a bug in Discourse, where Discourse cannot correctly detect the server ssl certificate.

---

<div class="post-metadata">

### Author: ![TallTrees](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/talltrees/32/208620_2.png) [@TallTrees](https://meta.discourse.org/u/TallTrees)
#### Post date: [January 20, 2021, 1:39pm UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/10 "2021-01-20T13:39:02Z")

</div>

This doesn’t sound like a bug in Discourse. It sounds like a problem in the host DNS resolver config or SSL certificate.

Since telnet doesn’t use SSL, I guess that’s why you found that to work. Under linux you may find you can get a bit further testing using OpenSSL to test the connection and examine certificates instead.

There is some info here which may help: [https://docs.pingidentity.com/bundle/solution-guides/page/iqs1569423823079.html](https://docs.pingidentity.com/bundle/solution-guides/page/iqs1569423823079.html)

---

<div class="post-metadata">

### Author: ![superman](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@superman](https://meta.discourse.org/u/superman)
#### Post date: [January 20, 2021, 2:27pm UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/11 "2021-01-20T14:27:33Z")

</div>

The https on the site is working because it shows the green padlock in the address bar. There is nothing wrong with the ssl certificate for the site. There is something wrong with the way Discourse detects the ssl certificate.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [January 20, 2021, 2:28pm UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/12 "2021-01-20T14:28:48Z")

</div>

That error is not about the site certificate, but about your SMTP service certificate.

---

<div class="post-metadata">

### Author: ![superman](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@superman](https://meta.discourse.org/u/superman)
#### Post date: [January 20, 2021, 3:10pm UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/13 "2021-01-20T15:10:09Z")

</div>

> [@Falco](#):
>
> SMTP service certificate

The SMTP service certificate is just the server’s ssl certificate, not the website’s ssl certificate. The server ssl certificate is correct, and working.

---

<div class="post-metadata">

### Author: ![superman](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@superman](https://meta.discourse.org/u/superman)
#### Post date: [January 20, 2021, 3:32pm UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/14 "2021-01-20T15:32:31Z")

</div>

For setting up a local SMTP server on the same machine as the Discourse container, Discourse does not specify exactly what the correct values for the SMTP settings in app.yml should be. This leads to a great deal of confusion and errors.

In the app.yml settings, Discourse does not clearly specify what the DISCOURSE\_SMTP\_ADDRESS is supposed to be.

In reality it is [subdomain.domain.com](http://subdomain.domain.com), and not [mail.subdomain.domain.com](http://mail.subdomain.domain.com)

```
Correct values:
DISCOURSE_SMTP_ADDRESS: forum.domain.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: postmaster@forum.domain.com
DISCOURSE_SMTP_PASSWORD: "password"
DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)

```

Discourse does not clearly specify what the “server certificate” is in this error statement that is present after sending the initial registration email fails. The error message is located in:  
/discourse/shared/standalone/log/rails/production.log  
“Job exception: hostname “[mail.forum.domain.com](http://mail.forum.domain.com)” does not match the server certificate”.

However, in reality, the “server certificate” is simply the server’s ssl certificate.  
Also, in the error message, Discourse incorrectly mentions “hostname”, when instead what is being referred to in reality is actually the DISCOURSE\_SMTP\_ADDRESS.

There was struggle because of Discourse’s ambiguity.

The solution was simply to set the server’s ssl certificate to the correct ssl certificate.

When the problem was posted to the Discourse forum, there were a lot of misleading and unclear answers.

Discourse should fix these problems.

---

<div class="post-metadata">

### Author: ![superman](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@superman](https://meta.discourse.org/u/superman)
#### Post date: [January 20, 2021, 6:06pm UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/15 "2021-01-20T18:06:52Z")

</div>

Now Discourse doctor is saying the email was sent:

```
Sending mail to admin@email.com. . . 
Testing sending to admin@email.com using forum.domain.com:587.
SMTP server connection successful.
Sending to admin@email.com. . . 
Mail accepted by SMTP server.

```

However, there is no email in the receiving mailbox or spam.

How can this problem be fixed?

---

<div class="post-metadata">

### Author: ![Syonyk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/syonyk/32/206551_2.png) [@Syonyk](https://meta.discourse.org/u/Syonyk)
#### Post date: [January 20, 2021, 10:43pm UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/16 "2021-01-20T22:43:02Z")

</div>

Look at the logs for your local SMTP server. If Discourse has properly delivered it to the SMTP server, it’s out of the hands of Discourse.

---

<div class="post-metadata">

### Author: ![superman](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@superman](https://meta.discourse.org/u/superman)
#### Post date: [January 21, 2021, 12:44am UTC](https://meta.discourse.org/t/unable-to-send-emails-using-local-smtp-server/176643/17 "2021-01-21T00:44:32Z")

</div>

In the Exim4 logs there is an error message, what does it mean?

`2021-01-21 00:39:39 H=(localhost.localdomain) [172.17.0.2] X=TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256 CV=no F=<noreply@forum.domain.com> A=dovecot_plain:postmaster@forum.domain.com rejected RCPT <admin@email.com>: Sender verify failed`
