Skip to content
Back

SMTP Error: Could not connect to SMTP host

  • 0
  • Self Hosted
  • General
Felipe Amaral
22 Apr, 2025, 18:16

My Appwrite is not sending emails. The following tests were performed to validate the environment variables:

Log:

TypeScript
appwrite-worker-mails  | [Worker] Worker 0 is ready!
appwrite-worker-mails  | Worker mails  started
appwrite-worker-mails  | [Job] Received Job (6807cd8c4a0ba8.90969113).
appwrite-worker-mails  | [Job] (6807cd8c4a0ba8.90969113) failed to run.
appwrite-worker-mails  | [Job] (6807cd8c4a0ba8.90969113) Error sending mail: SMTP Error: Could not connect to SMTP host.
appwrite-worker-mails  | Using deprecated logging configuration. Please update your configuration to use DSN format.Unable to parse DSN: scheme is required
appwrite-worker-mails  | [Error] Type: Exception
appwrite-worker-mails  | [Error] Message: Error sending mail: SMTP Error: Could not connect to SMTP host.
appwrite-worker-mails  | [Error] File: /usr/src/code/src/Appwrite/Platform/Workers/Mails.php
appwrite-worker-mails  | [Error] Line: 145

Variables:

TypeScript
docker compose exec appwrite-worker-mails vars | grep SMTP
- _APP_SMTP_HOST=mail.***
- _APP_SMTP_PORT=465
- _APP_SMTP_SECURE=tls
- _APP_SMTP_USERNAME=infra@***
- _APP_SMTP_PASSWORD=***

openssl test:

TypeScript
docker compose exec appwrite-worker-mails sh -c "openssl s_client -connect \$_APP_SMTP_HOST:\$_APP_SMTP_PORT"
Connecting to 192.*.*.*
CONNECTED(00000003)
depth=2 C=US, O=Internet Security Research Group, CN=ISRG Root X1
verify return:1
depth=1 C=US, O=Let's Encrypt, CN=R11
verify return:1
depth=0 CN=mail.***
verify return:1

...

220-*** ESMTP Exim 4.98.1 #2 Tue, 22 Apr 2025 15:05:35 -0300
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
TL;DR
Developers are facing an SMTP Error when trying to connect to the SMTP host. They discovered that changing the tls to 1.2 in the openssl command resolved the issue. However, their Appwrite is still not sending emails. The log shows an error "SMTP Error: Could not connect to SMTP host." The environment variables and openssl test seem to be correctly configured. Solution: Update the tls configuration in the provided shell script to tls1_2 instead of tls1.
Felipe Amaral
22 Apr, 2025, 18:18

I found this command to test.

TypeScript
#!/bin/sh
TO=email@mydomain.com
if [ ! -z "$1" ]; then
    TO=$1
fi
COMMAND='echo -e "From: <$_APP_SYSTEM_EMAIL_ADDRESS>\nSubject: Test SMTP Connection" | sendmail -H "openssl s_client -quiet -tls1 -connect $_APP_SMTP_HOST:$_APP_SMTP_PORT" -au$_APP_SMTP_USERNAME -ap$_APP_SMTP_PASSWORD -f $_APP_SYSTEM_EMAIL_ADDRESS -v'
COMMAND="${COMMAND} ${TO}"
docker compose exec appwrite-worker-mails sh -c "$COMMAND"

Output:

TypeScript
sendmail: send:'NOOP'
Connecting to 192.*.*.*
288B5D80E17F0000:error:0A0000BF:SSL routines:tls_setup_handshake:no protocols available:ssl/statem/statem_lib.c:153:
sendmail: NOOP failed
sendmail: helper exited (1)

When change the tls to 1.2 in openssl command it works fine.

tls1_2:

TypeScript
sendmail: send:'NOOP'
Connecting to 192.185.131.88
depth=2 C=US, O=Internet Security Research Group, CN=ISRG Root X1
verify return:1
depth=1 C=US, O=Let's Encrypt, CN=R11
verify return:1
depth=0 CN=mail.***
verify return:1
sendmail: recv:'220-***.com ESMTP Exim 4.98.1  

... 

sendmail: recv:'235 Authentication succeeded'
sendmail: send:'MAIL FROM:<noreply@***>'
sendmail: recv:'250 OK'
sendmail: send:'RCPT TO:<infra@***>'
sendmail: recv:'250 Accepted'
sendmail: send:'DATA'
sendmail: recv:'354 Enter message, ending with "." on a line by itself'
sendmail: send:'From: <noreply@***>'
sendmail: send:'Subject: Test SMTP Connection'
sendmail: send:'To: infra@***'
sendmail: send:''
sendmail: send:'.'
sendmail: recv:'250 OK id=1u7I5T-00000001X5Q-2clT'
sendmail: send:'QUIT'
sendmail: recv:'221 ***.com closing connection'
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more