SMTP setup not working

I was trying to enable SMTP emails for the on-premise docker server I have running on EC2, for which I did the following changes in sentry/config.yml

mail.host: '<removed>'
mail.port: 25
mail.username: '<removed>'
mail.password: '<removed>'
mail.use-tls: true
# The email address to send on behalf of
mail.from: '<removed>'

Then I ran ./install.sh.
But for some reason sentry got upgrade to 21.5 when im pretty sure it was 21.3 earlier. AFAIK, I had not done a Git pull or anything.

Regardless the service ran fine on accessing it, but I am no longer able to send events to it, i.e., any new events sent to sentry are no longer shown. I am also seeing a bunch of errors in compose logs, especially in relay, snuba-replacer, snuba-sessions-consumer, snuba-outcomes-consumer, snuba-consumer, snuba-transactions-consumer, subscription-consumer-events, subscription-consumer-transactions

Since then I have tried to git pull and install again, to update to latest version, and tried to install 21.3 again, nothing seems to work. I have also reverted config.yml to its original state and re-run installation, still Sentry does not catch errors

I actually managed to somehow solve this by pulling on master branch and running install.sh a few times, till everything fixed itself somehow.

Though I am still struggling with making SMTP emails work. I just this error.

web_1                                       | 14:12:58 [INFO] sentry.superuser: superuser.request 
            (url='http://sentry.<removed>.com/api/0/internal/mail/' method='POST' 
             ip_address='188.241.81.122' user_id=1)
nginx_1                                     | 172.20.0.1 - - [05/May/2021:14:12:58 +0000] "POST 
               /api/0/internal/mail/ HTTP/1.0" 500 42 
               "https://sentry.<removed>.com/manage/status/mail/" "Mozilla/5.0 (X11; 
                Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 
                Safari/537.36" "188.241.81.122"

The config used is

mail.backend: 'smtp'  # Use dummy if you want to disable email entirely
#mail.host: 'smtp'
mail.host: 'smtp.sendgrid.com'
mail.port: 587
mail.username: 'apikey'
mail.password: '<removed>'
#mail.use-tls: true
# The email address to send on behalf of
mail.from: '<removed>'

I manually tested from the host machine, I am able to send emails via Telnet

Can anyone help me debug this setup to get SMTP emails working?

version: 21.5.1
system: CentOS 7.9
similar error

web_1                                       | 05:51:09 [INFO] sentry.superuser: superuser.request (url='http://118.190.63.137/api/0/internal/mail/' method='POST' ip_address='27.211.206.249' user_id=1)
nginx_1                                     | 2021/06/23 05:51:17 [error] 7#7: *382 upstream prematurely closed connection while reading response header from upstream, client: 27.211.206.249, server: , request: "POST /api/0/internal/mail/ HTTP/1.1", upstream: "http://172.18.0.28:9000/api/0/internal/mail/", host: "118.190.63.137:9000", referrer: "http://118.190.63.137:9000/manage/status/mail/"
nginx_1                                     | 27.211.206.249 - - [23/Jun/2021:05:51:17 +0000] "POST /api/0/internal/mail/ HTTP/1.1" 502 552 "http://118.190.63.137:9000/manage/status/mail/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36" "-"