Back

[SOLVED] Can't get SMTP to send e-mails

  • 0
  • Self Hosted
  • General
hernik
20 Aug, 2023, 12:12

Hello, I am trying to get sending e-mails through appwrite to work, however each time an e-mail is supposedly sent, it doesn't actually get sent. The worker-mails container logs return the following:

TypeScript
...has failed Exception: Error sending mail: SMTP Error: Could not connect to SMTP host. in /usr/src/code/app/workers/mails.php:68
Stack trace:
#0 /usr/src/code/src/Appwrite/Resque/Worker.php(122): MailsV1->run()
#1 /usr/src/code/vendor/resque/php-resque/lib/Resque/Job.php(201): Appwrite\Resque\Worker->perform()
#2 /usr/src/code/vendor/resque/php-resque/lib/Resque/Worker.php(303): Resque_Job->perform()
#3 /usr/src/code/vendor/resque/php-resque/lib/Resque/Worker.php(242): Resque_Worker->perform(Object(Resque_Job))
#4 /usr/src/code/vendor/resque/php-resque/bin/resque(185): Resque_Worker->work('1', false)
#5 {main}

I have tried two different external SMTP services, one which we use for mails (seznam.cz) and now Sendgrid and I am 100% sure that the credentials are correct. My VPS provider should not be blocking them, because I can succesfully telnet to them both.

TL;DR
User is unable to send emails through SMTP in Appwrite. They tried different SMTP services and verified that the credentials are correct. They can successfully telnet to the SMTP servers. The `docker compose exec appwrite-worker-mails vars` command returns the current SMTP configuration. When running `appwrite doctor`, the SMTP step hangs but the output shows that SMTP is disconnected. In the `worker-mails` container logs, an error is thrown while trying to send mail. Solution: 1. Try changing the SMTP port from 465 to 587 in the SMTP configuration. 2. Verify that the hostname and CNAME target have public suffixes.
hernik
20 Aug, 2023, 12:12

When I tried to run appwrite doctor, each time it would hang for a few minutes on the SMTP step, however here is the output:

TypeScript
  __   ____  ____  _  _  ____  __  ____  ____     __  __
 / _\ (  _ \(  _ \/ )( \(  _ \(  )(_  _)(  __)   (  )/  \
/    \ ) __/ ) __/\ /\ / )   / )(   )(   ) _)  _  )((  O )
\_/\_/(__)  (__)  (_/\_)(__\_)(__) (__) (____)(_)(__)\__/

👩‍⚕️ Running Appwrite Doctor for version 1.3.6 ...

Checking for production best practices...
🟢 Hostname has a public suffix (aw.mydomain.tld)
🟢 CNAME target has a public suffix (aw.mydomain.tld)
🟢 Using a unique secret key for encryption
🟢 App environment is set for production
🟢 Abuse protection is enabled
🟢 Console access limits are enabled
🔴 HTTPS force option is disabled
🔴 Logging adapter is disabled

Checking connectivity...
Database............connected 👍
Queue...............connected 👍
Cache...............connected 👍
SMTP.............disconnected 👎
StatsD..............connected 👍
InfluxDB............connected 👍

Checking volumes...
🟢 Uploads Volume is readable
🟢 Uploads Volume is writeable
🟢 Cache Volume is readable
🟢 Cache Volume is writeable
🟢 Config Volume is readable
🟢 Config Volume is writeable
🟢 Certs Volume is readable
🟢 Certs Volume is writeable

Checking disk space usage...
🟢 Uploads Volume has 34.44GB free space (31.67% used)
🟢 Cache Volume has 34.44GB free space (31.67% used)
🟢 Config Volume has 34.44GB free space (31.67% used)
🟢 Certs Volume has 34.44GB free space (31.67% used)

Failed to check for a newer version
hernik
20 Aug, 2023, 12:14

Current SMTP config (returned through docker compose exec appwrite-worker-mails vars):

TypeScript
- _APP_SMTP_HOST=smtp.sendgrid.net
- _APP_SMTP_PORT=465
- _APP_SMTP_SECURE=tls
- _APP_SMTP_USERNAME=apikey
- _APP_SMTP_PASSWORD=mypassword
Drake
21 Aug, 2023, 02:13

So you telnet to that host and port and it works?

hernik
21 Aug, 2023, 14:56

Yes

Drake
21 Aug, 2023, 14:57

you telnet from your appwrite server?

hernik
21 Aug, 2023, 15:02

from the ssh where the docker compose is running, not from any of the actual containers

Drake
21 Aug, 2023, 15:02

and what was the telnet command you ran?

hernik
21 Aug, 2023, 15:03

telnet smtp.sendgrid.net 465

hernik
21 Aug, 2023, 15:03

Response is

TypeScript
Trying 18.197.194.208...
Connected to smtp.sendgrid.net.
Escape character is '^]'.
Drake
21 Aug, 2023, 15:04

interesting...can you try downloading this script into your appwrite folder and try to run it? https://gist.github.com/stnguyen90/869ca2addbc2f61e17490fc468932e6a

Drake
21 Aug, 2023, 15:05

and who's your vps provider?

hernik
21 Aug, 2023, 15:06

Contabo

hernik
21 Aug, 2023, 15:06

Script returns

TypeScript
sendmail: send:'NOOP'
write:errno=0
sendmail: NOOP failed
Drake
21 Aug, 2023, 15:06

can you try changing port 465 to 587?

hernik
21 Aug, 2023, 15:08

now the script returns

TypeScript
sendmail: send:'NOOP'
140130297396040:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:ssl/record/ssl3_record.c:331:
sendmail: helper exited (1)
hernik
21 Aug, 2023, 15:13

Oh but it works

hernik
21 Aug, 2023, 15:13

The e-mail has come through

Drake
21 Aug, 2023, 15:14

nice how about the doctor script now?

hernik
21 Aug, 2023, 15:15

shows SMTP................connected 👍

hernik
21 Aug, 2023, 15:16

Thanks a lot!

Drake
21 Aug, 2023, 15:16

[SOLVED] Can't get SMTP to send e-mails

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