CLI email sends fine, Discourse send gets 422


I can send an email from the CLI [1], but when I send from Discourse [2] I get this 422 error which to me is too non-specific to figure out. Credentials, servername, port are the same in both cases. Help?

[1] ========== CLI send, works and email is received ==========

$swaks --to --from {redacted} --server --auth LOGIN --auth-user server{redacted}
Password: {redacted}
=== Trying
=== Connected to
<-  220 Hurricane Server ESMTP service ready.
 -> EHLO nbb-rc-1604-2
<- Hello [{redacted}]
<-  250-SIZE 0
<-  250-STARTTLS
<-  250-AUTH=LOGIN
<-  250 OK
<-  334 VXNlcm5hbWU6
 -> {redacted}
<-  334 UGFzc3dvcmQ6
 -> {redacted}
<-  235 2.7.0 Accepted.
 -> MAIL FROM:<{redacted}>
<-  250 2.1.0 sender {redacted} OK
 -> RCPT TO:<>
<-  250 2.1.5 recipient OK
 -> DATA
<-  354 Send data.  End with CRLF.CRLF
 -> Date: Mon, 10 Sep 2018 05:03:54 +0000
 -> To:
 -> From: {redacted}
 -> Subject: test Mon, 10 Sep 2018 05:03:54 +0000
 -> X-Mailer: swaks v20130209.0
 -> This is a test mailing
 -> .
<-  250 2.0.0 Message received and queued as 87000000c634fd.
 -> QUIT
<-  221 Closing. Have a good day.
=== Connection closed with remote host.

[2] ========== Discourse send, fails ==========

Started POST "/admin/email/test" for {redacted} at 2018-09-10 05:11:15 +0000
Processing by Admin::EmailController#test as */*
  Parameters: {"email_address"=>""}
Sent mail to (830.2ms)
Completed 422 Unprocessable Entity in 1106ms (Views: 0.2ms | ActiveRecord: 4.2ms)

(Jay Pfaffman) #2

You might try discourse-doctor (or the rake task that it calls (.


Well, yeah. I did use Discourse Doctor, but it gave an even more opaque result:

==================== MAIL TEST ====================
For a robust test, get an address from
Or just send a test message to yourself.
Email address for mail test? ('n' to skip) []: {redacted}
Sending mail to {redacted}. . . 
Testing sending to {redacted} using {redacted}:{redacted}
SMTP server connection successful.
Sending to {redacted}. . . 
Sending mail failed.
Replacing: Sending mail to

==================== DONE! ====================

And in the linked error file:

==================== MAIL TEST ====================
For a robust test, get an address from
Sending mail to REDACTED  . . 
Testing sending to {redacted} using
SMTP server connection successful.
Sending to {redacted}. . . 
Sending mail failed.

==================== DONE! ====================


I guess what I am looking for is a smtp session log like what swaks gives. Or some actual error trace…

Looking at the Discourse forum, the “422” error is usually a result of 2FA or other unusual auth requirements of the various SMTP providers. In my case, I am using the simplest and most widely used transactional email provider that exists, to which I can send just fine from CLI.

(Jay Pfaffman) #5

Hmm. Thanks very much for the info. I just started coming up with whatever errors Discourse doctor can catch and diagnose.

According to, 422 for an SMTP server means:

The recipient’s mailbox has exceeded its storage limit.

Could that be true?

(Michael - #6

The 422 is an HTTP error (Unprocessable Entity), not a SMTP error.

Since sending through CLI goes well, this must be on the Discourse web app side.

(Jay Pfaffman) #7

But his above message from discourse-doctor did fail. His success was from swaks, not Discourse.


I am going to guess that the issue is along these lines:

…and then I start crying.



That said, I would NEXT guess that I have an environment issue… which means reinstall. Sigh. So, that is my next step barring any other input. I’ll tell you all how it goes.


Well, after several reinstalls including one on CentOS and now one on Debian… I still cannot get emails to send. Its sort of magical. I can send successfully on all the servers I have built from the server env, and from within the docker container. But hell if I can get discourse to send.

So… are there any volunteers out there with working dev environments that would take my email server credentials and see if they can send a test email?


(Jay Pfaffman) #12

My guess is that your mail server didn’t like the address that Discourse was using. If you look in app.yml there is a comment that shows how to set the sending address.

Have you checked the mail logs?


mail logs? I think… its just 500… unknown command or some crap.

And yeah, I am going to try a different email service next. I really like socketlabs, but who knows, maybe they are the issue.

(Jay Pfaffman) #14

I meant the mail logs at the mail service.

Mail is just insanely hard.


I have always thought mail was easy. I have written a couple PHP mailers (wrappers) myself. It is pretty straight forward.

And, socketlabs never even gets the connection… however this does not obviate the possibility that their routers are dropping the connection before it gets to their mail servers.

sigh… we shall try again.


afaik this issue is with the secure connection. That is all I know, and I still fail to connect.

My desire to use discourse is almost sadistic at this point.

(Jeff Atwood) #18

That’s where you went wrong … :wink: easily in the top 5 support requests we get, setting up email servers is very difficult – that is the nature of the :email: beast.


Well, I ended up using the digital ocean Ubuntu 18.04 Discourse image… that worked. What a crazy issue.