Emails with local SMTP

(Maestro Magnifico) #1

Till this moment I used Discourse on Debian 7 using this guide:

Emails worked right after I did apt-get install postfix, without SMTP at all.

Now I’m trying Discourse on Ubuntu using this guide:

But I have no luck with sending emails yet. I don’t want to use Mandrill at all (because why should I?). And emails doesn’t work after apt-get install postfix, I guess because Discourse doesn’t set up to work with postfix by default, unlike version.

Did anyone else tried to set up Discourse to send emails from same server? And… not failed horribly like I did?

Email error. Unable to send out email
Configuring Discourse on localhost - Can't get past mail
Beginners Guide to Install Discourse on Ubuntu for Development
(Jeff Atwood) #2

Hold on to your britches because email is the hardest problem in computer science. Not even joking.

There is a reason we tell people to use Mandrill, and it is 100% free until you send 12k emails per month. What’s the downside? Nothing that I can see, unless you send tons and tons of email. For most small and medium Discourse instances 12k is far beyond what you’d send in a month.

And of course we can only support the Docker based install, which requires the use of Mandrill or some other external SMTP server.

Straightforward direct-delivery incoming mail
(Maestro Magnifico) #3

Wut? I code PHP, all my previous forums was on PHP and there’s default function that sends emails perfectly fine. You telling me that there is no analogs for it in Ruby?

(Jeff Atwood) #4

Sorry I should have been more clear. Setting up an EMAIL SERVER.

But yeah, even sending an email in code is hard if you know what you are doing and want the email to actually arrive

(Kevin P. Fleming) #5

That function does not actually send email, it constructs the message and hands it off to a server for processing.

(Kevin P. Fleming) #6

Postfix is an SMTP server :slight_smile:

(Maestro Magnifico) #7

Lol. I’m not a linux guy on my work, I only code and have no idea how some things works. :laughing: Thx for the tip, I’m gonna google how to setup login and password for postfix and will try to use localhost SMTP in Discourse. It should work since it works in package for Debian.

(Kane York) #9


There’s your problem. Localhost for the container is not localhost on the host.

Change that to your host’s publicly routable IP, and change your firewall to allow from the range.

(Maestro Magnifico) #10

Why exactly?

(Kane York) #11

Because those are reserved IPs (for local) and what Docker chooses its IPs from.

(Allen - Watchman Monitoring) #12

I think you may want to disable ssl/tls for localhost too

sample for disabling starttls (local smtp, etc) by YesThatAllen · Pull Request #103 · discourse/discourse_docker · GitHub

(Maestro Magnifico) #13

Soooo, it works. I had to add this in app.yml in env section:


Then I did ./launcher rebuild app
Other mail directives in app.yml looks like this (mostly commented):

DISCOURSE_SMTP_ADDRESS:         # (mandatory)
#DISCOURSE_SMTP_PORT: 587                        # (optional)
#DISCOURSE_SMTP_USER_NAME:      # (optional)
#DISCOURSE_SMTP_PASSWORD: pa$$word               # (optional)

And here’s how my from /etc/postfix looks like:

# See /usr/share/postfix/ for a commented, more complete version

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination =,, localhost
mynetworks = [::ffff:]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

I’m not sure if this setup safe or not, but it works for now. If someone have advice on how to make this setup more optimal, please share. I’m trying to setup other stuff for now.

(Maestro Magnifico) #14

Btw, although Discourse sends emails fine ./launcher mailtest app still not working for some reason. It shows this:

So I just dropped using it. I used Discourse front-end instead to test email sending. What I did was I tried to login as admin over and over again, resending confirmation email and playing with Postfix settings. And it worked at some point.

(Rahul Kumar) #15


Hey man , i am also stuck with some similar kind of issue.

I have this postfix setup ready and i am able to send mail through command line . But when i try sending Test mail through my discourse, its not able to send. I have configured smtp server according to postfix.
How to debug the issue ?? Discourse is not even trying to send the mail , i checked the discourse mail log, no mail there.
Any leads on this please , stuck on it from past one week.

My discourse config values are

# address of smtp server used to send emails
smtp_address =

# port of smtp server used to send emails
smtp_port = 25

# domain passed to smtp server
smtp_domain =

# username for smtp server
smtp_user_name =

# password for smtp server
smtp_password =

# smtp authentication mechanism
smtp_authentication = none

# enable TLS encryption for smtp connections
smtp_enable_start_tls = false

# mode for verifying smtp server certificates
# to disable, set to 'none'
smtp_openssl_verify_mode = none


(Flap Jack) #16

Same here, according to the logs no emails are sent after initial account creation.

When logging in to resend the activation email, it seems to send, but as pointed out Setting up DISCOURSE_SMTP_ADDRESS: 'localhost'? these never arrive either.

Started POST "/users/action/send_activation_email" at 2015-06-16 02:49:23 +0200
Processing by UsersController#send_activation_email as */*
  Parameters: {"username"=>"forumworld2000"}
  Rendered text template (0.1ms)
Completed 200 OK in 292ms (Views: 2.9ms | ActiveRecord: 42.6ms)

Yes, I’m not using the official Docker image, so I’m not really entitled to help. But this way I’m sure that my localhost is not being blocked by any containers. Also, sending emails from localhost works fine with other Rails apps on this server.

Anybody aware of any ways to debug this?

(Kane York) #17

If you’re running in development, you need to bundle exec sidekiq every so often to have the deferred tasks be processed.

(Flap Jack) #18

Cool, I didn’t know that.

This is production, however. Aside from PostgreSQL, the only thing I have running in addition to the app itself is Redis. Do I need to start any other daemons too maybe?

I’m not entirely done going through all the Docker templates so apologies if I’m missing something obvious.

(Flap Jack) #19

I am absolutely stumped. Why won’t Discourse send emails from my localhost when other Rails apps manage to just fine?

Using Rahul_Kumar’s configuration.

(Sam Saffron) #20

Sorry, the only production based setup we support here is the docker based installs

(Allen - Watchman Monitoring) #21

One reason is that if your discourse instance is running in a container, it’s localhost is not where your postfix, etc live.

They would have to be looking to the host’s IP address, and your local host would need to know to whitelist the container’s IP range:


mynetworks = [::ffff:]/104 [::1]/128