Email Inboxes Setup with Gmail

Description

I am trying to setup email support in rocketchat omnichannel using the Email Inboxes feature, but it’s very random at times, sometimes smtp connection times out or imap connection times out but I still manage it to get it working in a few tries. Most recently everything was setup correctly and started working in a test workspace i setup using docker at test instance using a test email id configured in our google suite. And in the process I realised google might be blocking connection from our url to smtp.gmail.com so we configured relay in google suite and connected with smtp-relay.gmail.com. Although I noticed a few errors or retries in docker container logs, I still got both smtp and imap working.

Once I transferred the same settings to our production workspace with our primary support email id, it didn’t work as expected, smtp got working properly but imap kept throwing errors related to connection timeout/authentication timeout. I verified all the login credentials like username/app password and everything is configured correctly including imap was also enabled from gmail inbox. I also tested manually connecting to gmail imap using openssl s_client and tried authenticating and it worked perfectly.

Even after multiples retries, toggling the feature on and off I just couldn’t get imap working in production.
After this i tried to configure the primary email id in our test workspace but that just resulted in the same error for both emails now. test email which was already working, started also failing after I toggled it on/off while adding prod email to test workspace.

So in conclusion it’s pretty finicky and sometimes smtp works/ imap works/ both work/ both fail/ both keeps getting timed out.

Server Setup Information

  • Version of Rocket.Chat Server: 6.6.6
  • Operating System: linux
  • Deployment Method: docker
  • Number of Running Instances: 2 or different ec2’s
  • DB Replicaset Oplog: Enabled
  • NodeJS Version: 14.21.3 - x64
  • MongoDB Version: 5.0.24
  • Proxy: nginx
  • Firewalls involved: No

Any additional Information

SMTP ERROR:

{"level":40,"time":"2024-04-02T06:54:53.806Z","pid":1,"hostname":"2c8b012b9692","name":"DeprecationWarning","section":"API","msg":"The parameter \"query\" in the endpoint \"/api/v1/emoji-custom.all\" is deprecated and will be removed on version 7.0.0"} 
{"level":50,"time":"2024-04-02T06:58:02.521Z","pid":1,"hostname":"2c8b012b9692","name":"EmailInbox","msg":"Error sending Email reply","err":{"type":"Error","message":"Server terminates connection. response=421-4.7.0 Try again later, closing connection. (EHLO)<br>421-4.7.0  For more information, go to<br>421 4.7.0  https://support.google.com/a/answer/3221692 ep22-20020a05622a549600b004309ccecaf6sm1124484qtb.3 - gsmtp: 421-4.7.0 Try again later, closing connection. (EHLO)<br>421-4.7.0  For more information, go to<br>421 4.7.0  https://support.google.com/a/answer/3221692 ep22-20020a05622a549600b004309ccecaf6sm1124484qtb.3 - gsmtp","stack":"Error: Server terminates connection. response=421-4.7.0 Try again later, closing connection. (EHLO)<br>421-4.7.0  For more information, go to<br>421 4.7.0  https://support.google.com/a/answer/3221692 ep22-20020a05622a549600b004309ccecaf6sm1124484qtb.3 - gsmtp: 421-4.7.0 Try again later, closing connection. (EHLO)<br>421-4.7.0  For more information, go to<br>421 4.7.0  https://support.google.com/a/answer/3221692 ep22-20020a05622a549600b004309ccecaf6sm1124484qtb.3 - gsmtp<br>    at SMTPConnection._actionEHLO (/app/bundle/programs/server/npm/node_modules/nodemailer/lib/smtp-connection/index.js:1248:27)<br>    at SMTPConnection._processResponse (/app/bundle/programs/server/npm/node_modules/nodemailer/lib/smtp-connection/index.js:950:20)<br>    at SMTPConnection._onData (/app/bundle/programs/server/npm/node_modules/nodemailer/lib/smtp-connection/index.js:752:14)<br>    at Socket.SMTPConnection._onSocketData (/app/bundle/programs/server/npm/node_modules/nodemailer/lib/smtp-connection/index.js:191:44)<br>    at Socket.emit (events.js:400:28)<br>    at Socket.emit (domain.js:475:12)<br>    at addChunk (internal/streams/readable.js:293:12)<br>    at readableAddChunk (internal/streams/readable.js:267:9)<br>    at Socket.Readable.push (internal/streams/readable.js:206:10)<br>    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)<br>    at TCP.callbackTrampoline (internal/async_hooks.js:130:17)","code":"ECONNECTION","response":"421-4.7.0 Try again later, closing connection. (EHLO)<br>421-4.7.0  For more information, go to<br>421 4.7.0  https://support.google.com/a/answer/3221692 ep22-20020a05622a549600b004309ccecaf6sm1124484qtb.3 - gsmtp","responseCode":421,"command":"EHLO"}} 

IMAP ERROR

{"level":50,"time":"2024-04-02T06:53:17.157Z","pid":1,"hostname":"4d06c6be9caf","name":"EmailInbox","msg":"IMAP error","err":{"type":"Error","message":"Timed out while authenticating with server","stack":"Error: Timed out while authenticating with server<br>    at Timeout._onTimeout (/app/bundle/programs/server/npm/node_modules/imap/lib/Connection.js:139:17)<br>    at listOnTimeout (internal/timers.js:557:17)<br>    at processTimers (internal/timers.js:500:7)","source":"timeout-auth"}} 
{"level":50,"time":"2024-04-02T06:53:17.158Z","pid":1,"hostname":"4d06c6be9caf","name":"EmailInbox","msg":"IMAP error","err":{"type":"Error","message":"Timed out while authenticating with server","stack":"Error: Timed out while authenticating with server<br>    at Timeout._onTimeout (/app/bundle/programs/server/npm/node_modules/imap/lib/Connection.js:139:17)<br>    at listOnTimeout (internal/timers.js:557:17)<br>    at processTimers (internal/timers.js:500:7)","source":"timeout-auth"}} 
{"level":50,"time":"2024-04-02T06:53:22.039Z","pid":1,"hostname":"4d06c6be9caf","name":"EmailInbox","msg":"IMAP error","err":{"type":"Error","message":"Timed out while connecting to server","stack":"Error: Timed out while connecting to server<br>    at Timeout._onTimeout (/app/bundle/programs/server/npm/node_modules/imap/lib/Connection.js:280:15)<br>    at listOnTimeout (internal/timers.js:557:17)<br>    at processTimers (internal/timers.js:500:7)","source":"timeout"}}