SMTP Error: Could not authenticate
π Reproduction steps
Configure a custom SMTP server as part of the appwrite selfhost docker installation (APP_SMTP*) in the .env file.
π Expected behavior
Emails should be send for password recovery or email verification when requested from the console.
π Actual Behavior
No emails are generated, instead the (appwrite-worker-mails) log shows
[Job] (68fb524fabcf82.31712895) Error sending mail: SMTP Error: Could not authenticate.
[Error] Type: Exception
[Error] Message: Error sending mail: SMTP Error: Could not authenticate.
[Error] File: /usr/src/code/src/Appwrite/Platform/Workers/Mails.php
[Error] Line: 173
The same smtp configuration works fine when configured as a custom SMTP server in the project settings and account verification links are generated through the API.
π² Appwrite version
Version 1.8.x
π» Operating system
Linux
π§± Your Environment
I'm self hosting a fresh install of appwrite 1.8.0 using docker.
π Have you spent some time to check if this issue has been raised before?
- [x] I checked and didn't find similar issue
π’ Have you read the Code of Conduct?
- [x] I have read the Code of Conduct
@Luo-En Are you using it for both in the .env variables and also inside the console?
Yes. I configured it as a custom SMTP server for my project and also configured the same server in the .env file for the appwrite instance. It works for the project (when I need it to send out verification emails or mfa codes) but it doesn't work when appwrite itself should send out emails (e.g. when I needed to recover the appwrite admin's password).
@Luo-En What if you leave it only for the SMTP? It's still not working?
What are the env varibales that you have set?
Also, after setting them, did you recreate the containers with docker compose up -d or `docker compose up -d --force-recreateΒ΄?
What's the result of docker exec appwrite doctor?
I started with only the SMTP settings in the .env and that didn't work. I was quite surprised to see that it worked in the project settings though.
I never used compose up-d --force-recreate, just docker compose up -d. Want me to try that?
[Settings]
π’ Hostname is valid ([redacted])
π’ CNAME record target is valid ([redacted])
π’ A record target is valid (127.0.0.1)
π’ AAAA record target is valid (::1)
π’ Using a unique secret key for encryption
π’ App environment is set for production
π΄ Abuse protection is disabled
π’ Console access limits are enabled
π΄ HTTPS force option is disabled
π΄ HTTPS force option is disabled for function/site domains
π΄ Logging adapter is misconfigured
[Connectivity]
π’ Console.DB(console)...............................connected
π’ Projects.DB(database_db_main).....................connected
π’ Cache(cache_redis_main)...........................connected
Warning: foreach() argument must be of type array|object, null given in /usr/src/code/src/Appwrite/Platform/Tasks/Doctor.php on line 177
π’ PubSub(pubsub)....................................connected
π΄ SMTP...........................................disconnected
[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
[Disk Space]
π’ Uploads Volume has 991.82GB free space (49.6% used)
π’ Cache Volume has 991.82GB free space (49.6% used)
π’ Config Volume has 991.82GB free space (49.6% used)
π’ Certs Volume has 991.82GB free space (49.6% used)
Yes, try that. What variables have you set?
_APP_SMTP_HOST=smtp.resend.com
_APP_SMTP_PORT=587
_APP_SMTP_SECURE=false
_APP_SMTP_USERNAME=resend
_APP_SMTP_PASSWORD=[redacted]
Same problem after docker compose up -d --force-recreate and trying to verify admin's email (also made sure I copied the password from the project settings into the .env file):
[Job] (68ff5ae18be1b9.45121464) failed to run.
[Job] (68ff5ae18be1b9.45121464) Error sending mail: SMTP Error: Could not authenticate.
[Error] Type: Exception
[Error] Message: Error sending mail: SMTP Error: Could not authenticate.
[Error] File: /usr/src/code/src/Appwrite/Platform/Workers/Mails.php
[Error] Line: 173
Try setting those envs: _APP_SYSTEM_EMAIL_NAME _APP_SYSTEM_EMAIL_ADDRESS
They were already set. I changed them to match my admin user but still same exception from appwrite-worker-emails.
Try this: _APP_SMTP_PORT=465 _APP_SMTP_SECURE=tls
After making the change make sure to run docker compose up -d
Slightly different exception:
[Job] Received Job (68ff7722d74976.64688351).
---- took several minutes ----
[Job] (68ff7722d74976.64688351) failed to run.
[Job] (68ff7722d74976.64688351) Error sending mail: SMTP Error: Could not connect to SMTP host.
[Error] Type: Exception
[Error] Message: Error sending mail: SMTP Error: Could not connect to SMTP host.
[Error] File: /usr/src/code/src/Appwrite/Platform/Workers/Mails.php
[Error] Line: 173
SMTP port 587 requires TLS, while port 465 requires SSL. You can configure this in your Appwrite .env file as follows:
Port 587: _APP_SMTP_SECURE="tls" Port 465: _APP_SMTP_SECURE="ssl"
After updating the .env file, run:
docker-compose up -d --build --force-recreate
docker compose logs -f appwrite-worker-mails
Iβm using this configuration on my Appwrite 1.8.0 instance on a VPS, and itβs working perfectly.
@usmandilmeer what of those: the tls one or SSL are you using?
Both 587/"tls" and 465/"ssl" give me the same exception:
[Job] Received Job (6900b9fa618753.22982664).
[Job] (6900b9fa618753.22982664) failed to run.
[Job] (6900b9fa618753.22982664) Error sending mail: SMTP Error: data not accepted.
[Error] Type: Exception
[Error] Message: Error sending mail: SMTP Error: data not accepted.
[Error] File: /usr/src/code/src/Appwrite/Platform/Workers/Mails.php
[Error] Line: 173
@usmandilmeer what of those: the tls one or SSL are you using?
I am using "tls" with port 587 and it is perfectly for my self hosted appwrite.
Both 587/"tls" and 465/"ssl" give me the same exception:
[Job] Received Job (6900b9fa618753.22982664). [Job] (6900b9fa618753.22982664) failed to run. [Job] (6900b9fa618753.22982664) Error sending mail: SMTP Error: data not accepted. [Error] Type: Exception [Error] Message: Error sending mail: SMTP Error: data not accepted. [Error] File: /usr/src/code/src/Appwrite/Platform/Workers/Mails.php [Error] Line: 173
Are you using a self-hosted SMTP server or a third-party provider?
For debugging, you can try using Gmail SMTP with an app password generated from your Gmail account as the SMTP password.
The error youβre seeing indicates an issue at the DATA stage of SMTP. This is the step where the email body and headers are sent.
data not accepted means the SMTP server rejected the email content or refused to accept the email for delivery.
We're getting closer: tried with gmail and that works. Then generated a fresh API key from resend.com (which is used as the SMTP password), their SMTP server and required username and got the same exception as above ('data not accepted'). So it seems to be something specific when using resend as SMTP server.
@Luo-En Oh Great for you! This means the resend SMTP server is rejecting the email. In SMTP, sending an email goes through several steps: HELO, MAIL FROM, RCPT TO, DATA, and QUIT. The issue is at the DATA stage, where the SMTP server is rejecting your delivery. This is not an issue with your Appwrite instance.
Previously, I was using SendPulse, but today I switched to my own custom SMTP server (also configured on the same VPS as my Appwrite:1.8.0 instance.), and it is working perfectly.
@usmandilmeer What remains is the question why the same configuration then works in my appwrite project settings. Emails generated there work fine (using resend.com). It's not a blocking issue for me now but it might make sense to investigate why the same settings work as an appwrite project SMTP server but not for the appwrite instance (console) itself.
@Luo-En I think the problem occurs when Appwrite sends emails using Resendβthere may be additional headers required by Resend that are causing the delivery to be rejected.
Currently, if Gmail SMTP is working and your issue with sending emails via the Appwrite instance is resolved, you can use it for Appwrite, while continuing to use Resend for regular emails.
I also get the SMTP could not authenticate error. I am using Appwrite verssion 1.6.0.
[Error] Type: Exception
[Error] Message: Error sending mail: SMTP Error: Could not authenticate.
[Error] File: /usr/src/code/src/Appwrite/Platform/Workers/Mails.php
[Error] Line: 145
But I am able to send an email from inside the appwrite-worker-mails container using swaks. Thus confirming SMTP credentials.
sudo docker compose exec appwrite-worker-mails sh
apk add --no-cache perl
curl -O https://jetmore.org/john/code/swaks/files/swaks-20240103.0/swaks
chmod +x swaks
apk add --no-cache perl-net-ssleay perl-io-socket-ssl
perl ./swaks --to [email protected] \
--from "$_APP_SYSTEM_EMAIL_ADDRESS" \
--server "$_APP_SMTP_HOST" \
--port "$_APP_SMTP_PORT" \
--auth LOGIN \
--auth-user "$_APP_SMTP_USERNAME" \
--auth-password "$_APP_SMTP_PASSWORD" \
--tls
I can also confirm my variables are set.
~/appwrite$ sudo docker exec appwrite-worker-mails env | grep _APP_SMTP
_APP_SMTP_PORT=587
_APP_SMTP_HOST=smtp.mailgun.org
[email protected]
_APP_SMTP_SECURE=tls
_APP_SMTP_PASSWORD=1234-abcd
~/appwrite$ sudo docker exec appwrite-worker-mails env | grep _APP_SYSTEM_EMAIL
[email protected]
_APP_SYSTEM_EMAIL_NAME=MyAppName
But when I make a request from my frontend to reset a password I get the authentication error. The request goes through with status code 201.
const response = await account.createRecovery(email, url);
~/appwrite$ sudo docker compose logs -t appwrite-worker-mails
appwrite-worker-mails | Received Job.
appwrite-worker-mails | failed to run.
appwrite-worker-mails | Error sending mail: SMTP Error: Could not authenticate.
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 authenticate.
appwrite-worker-mails | File: /usr/src/code/src/Appwrite/Platform/Workers/Mails.php
appwrite-worker-mails | [Error] Line: 145
Fixed my SMTP authentication error. Email setting in the Appwrite console were different from the SMTP values in the .env file of self-hosted instance.
https://www.sunnyappdev.com/blog/mailgun-smtp-self-hosted-appwrite