422 Unprocessable Entity while sending email


I am trying to get my emails out using GSuit (Google Apps). If using the Gmail SMTP server with user authentication, email works fine, but all emails will be sent from the user account authenticating with Google.

When using the preferred way, sending mails through the GSuit SMTP Relay server smtp-relay.gmail.com without user authentication, then I am getting this error in the logs:

422 Unprocessable Entity

Full log excerpt:

Started GET "/admin/email.json?_=1498667751835" for at 2017-06-28 17:14:50 +0000
Processing by Admin::EmailController#index as JSON
  Parameters: {"_"=>"1498667751835"}
Completed 200 OK in 6ms (Views: 0.5ms | ActiveRecord: 0.0ms)
Started POST "/admin/email/test" for at 2017-06-28 17:14:52 +0000
Processing by Admin::EmailController#test as */*
  Parameters: {"email_address"=>"email@removed.com"}

Sent mail to email@removed.com (13.4ms)
Completed 422 Unprocessable Entity in 381ms (Views: 0.2ms | ActiveRecord: 3.1ms)

Discourse at this point says that the email couldn’t be sent and I should check my mail host.

I am pretty sure the GSuit part is configured correctly (fixed IP set, set to no authentication, set to allow any from: address).

This error doesn’t really make sense to me. I found another thread that reported the same error, but that was never fixed because the guy switched to a different mail provider.

Any clues?


1 Like

File a ticket with gmail.

That was definitely helpful, thanks a lot

I didn’t mean to sound curt. I believe that you have, in fact, configured stuff correctly, and that Gmail’s not delivering it. You’re not to blame. Discourse isn’t to blame.

Only they can know what the problem is.

How can you be so sure? The error message seems to suggest something is wrong with how the content is delivered to Google. The GMail logs don’t even show a connection attempt from the forums. So from where I stand, the email is never leaving the forum in the first place.

I’m not sure. But from what you said the previous solution has been to change mail providers. :slight_smile:

That’s info we didn’t have before.

Can you connect to the Gmail server from your host? Perhaps the IP that you think your server has isn’t the one that Gmail sees & it’s not allowed to connect (or something of that sort).

Yes, I can connect (disregard my previous post please, I was using the wrong port):

root@forums:/var/discourse# telnet smtp-relay.gmail.com 587
Connected to gmail-smtp-relay.l.google.com.
Escape character is '^]'.
220 smtp-relay.gmail.com ESMTP y6sm455188qka.8 - gsmtp

I am dealing with this same issue now on a new forum. We are trying to use the gmail relay for non-technical reasons (it’s used in our org for other things), but I can’t get it to delivery emails. Telnet to the service on 587 works, but discourse can’t send mails.

I’m getting Completed 422 Unprocessable Entity as well in the rails production.log for any mails being sent, such as to mail-tester.com or any other valid address. SMTP provider (SparkPost) seeing nothing in its logs.

  • Telnet to the SMTP host on 587 works fine.
  • Manual encoding of AUTH LOGIN to the mailserver works fine via telnet.

EDIT: Never mind, I removed DISCOURSE_SMTP_AUTHENTICATION: login from app.yml and did a ./launcher rebuild app and everything is working again.