Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit 75737e6

Browse files
authored
Merge pull request #38 from appwrite/fix-email-delivery-docs
feat: improve email docs
2 parents e8d9472 + 8f00da5 commit 75737e6

File tree

1 file changed

+53
-86
lines changed

1 file changed

+53
-86
lines changed
Lines changed: 53 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,71 @@
1-
<p>Appwrite above 0.7 version, by default comes with SMTP disabled and warning regarding email messages. In order for emails to work, you will need to setup proper SMTP configuration as described below.</p>
2-
3-
<p>Because email deliverability can be both tricky and hard, it is often easier to delegate this responsibility to a 3rd-party SMTP provider. This provider help you abstract the complexity of passing SPAM filters by doing a lot of the advanced configuration and validation for you.</p>
4-
5-
<p>In this document, you will learn how to connect your own SMTP server or a 3rd party SMTP provider like MailGun or SendGrid with Appwrite to help you get better email deliverability.</p>
6-
7-
<h2>Update your docker-compose.yml File</h2>
8-
9-
<p>Appwrite offers multiple environment variables to customize your server setup to your needs. To make Appwrite use your own SMTP server instead of the default build-in SMTP server, you need to change the Appwrite container environment variables.</p>
10-
11-
<div class="ide margin-bottom" data-lang="yaml" data-lang-label="yaml">
12-
<pre class="line-numbers"><code class="prism language-yaml" data-prism>appwrite:
13-
image: appwrite/appwrite:<?php echo APP_VERSION_STABLE . "\n"; ?>
14-
restart: unless-stopped
15-
networks:
16-
- appwrite
17-
labels:
18-
- traefik.http.routers.appwrite.rule=PathPrefix(`/`)
19-
- traefik.http.routers.appwrite-secure.rule=PathPrefix(`/`)
20-
- traefik.http.routers.appwrite-secure.tls=true
21-
volumes:
22-
- appwrite-uploads:/storage/uploads:rw
23-
- appwrite-cache:/storage/cache:rw
24-
- appwrite-config:/storage/config:rw
25-
- appwrite-certificates:/storage/certificates:rw
26-
depends_on:
27-
- mariadb
28-
- redis
29-
- smtp
30-
- clamav
31-
- influxdb
32-
- telegraf
33-
environment:
34-
- _APP_ENV=production
35-
- _APP_OPENSSL_KEY_V1=your-secret-key
36-
- _APP_DOMAIN=localhost
37-
- _APP_DOMAIN_TARGET=localhost
38-
- _APP_REDIS_HOST=redis
39-
- _APP_REDIS_PORT=6379
40-
- _APP_DB_HOST=mariadb
41-
- _APP_DB_PORT=3306
42-
- _APP_DB_SCHEMA=appwrite
43-
- _APP_DB_USER=user
44-
- _APP_DB_PASS=password
45-
- _APP_INFLUXDB_HOST=influxdb
46-
- _APP_INFLUXDB_PORT=8086
47-
- _APP_STATSD_HOST=telegraf
48-
- _APP_STATSD_PORT=8125
49-
- _APP_SMTP_HOST=smtp.mailgun.org
50-
- _APP_SMTP_PORT=587
51-
- _APP_SMTP_SECURE=tls
52-
- _APP_SMTP_USERNAME=YOUR-SMTP-USERNAME
53-
- _APP_SMTP_PASSWORD=YOUR-SMTP-PASSWORD
54-
</code></pre>
55-
</div>
1+
<p>Appwrite v0.7 and above come with support for easy integrations with 3rd party SMTP providers. In order for emails to work, you will need to setup proper SMTP configuration as described below.</p>
2+
3+
<p>Because email deliverability can be both tricky and hard, it is often easier to delegate this responsibility to a 3rd-party SMTP provider. These providers help you abstract the complexity of passing SPAM filters by doing a lot of the advanced configuration and validation for you.</p>
4+
5+
<p>In this document, you will learn how to connect a 3rd party SMTP provider like MailGun or SendGrid with Appwrite to help you get better email deliverability.</p>
566

57-
<p><b>_APP_SMTP_HOST</b> - SMTP server host name address. Default value is: ‘smtp’</p>
7+
<h2>Update Your .env File</h2>
588

59-
<p><b>_APP_SMTP_PORT</b> - SMTP server TCP port. Default value is: ‘25’</p>
9+
<p>At this stage, we assume that you have already installed Appwrite. Else, you can follow our <a href="/docs/installation">Getting Started Guide</a> for the installation. Appwrite offers multiple environment variables to customize your server setup to your needs. To configure Appwrite to use your own SMTP server, you need to set the following environment variables in the hidden .env file that comes with your Appwrite installation.</p>
10+
11+
<p><b>_APP_SMTP_HOST</b> - SMTP server host name address. Use an empty string to disable all mail sending from the server. The default value for this variable is an empty string</p>
12+
13+
<p><b>_APP_SMTP_PORT</b> - SMTP server TCP port. Empty by default.</p>
6014

6115
<p><b>_APP_SMTP_SECURE</b> - SMTP secure connection protocol. Empty by default, change to ‘tls’ if running on a secure connection.</p>
6216

6317
<p><b>_APP_SMTP_USERNAME</b> - SMTP server user name. Empty by default.</p>
6418

6519
<p><b>_APP_SMTP_PASSWORD</b> - SMTP server user password. Empty by default.</p>
6620

67-
<h2>Remove the Default SMTP Container</h2>
68-
69-
<p>If you are using Appwrite 0.7 or below, the Appwrite default setup includes the Appwrite default SMTP container. Now that you are using your own SMTP server setting, you don’t need it anymore. Just remove the SMTP container and relevant dependencies from your docker-compose.yml file:</p>
70-
71-
<div class="ide margin-bottom" data-lang="yaml" data-lang-label="yaml">
72-
<pre class="line-numbers"><code class="prism language-yaml" data-prism>appwrite:
73-
image: appwrite/appwrite:latest
74-
...
75-
depends_on:
76-
- mariadb
77-
- redis
78-
-̶ ̶s̶m̶t̶p̶
79-
- clamav
80-
- influxdb
81-
- telegraf̶
82-
83-
...
84-
85-
s̶m̶t̶p̶:̶
86-
̶ ̶ ̶ ̶ ̶i̶m̶a̶g̶e̶:̶ ̶a̶p̶p̶w̶r̶i̶t̶e̶/̶s̶m̶t̶p̶:̶1̶.̶0̶.̶1̶
87-
̶ ̶ ̶ ̶ ̶r̶e̶s̶t̶a̶r̶t̶:̶ ̶u̶n̶l̶e̶s̶s̶-̶s̶t̶o̶p̶p̶e̶d̶
88-
̶ ̶ ̶ ̶ ̶n̶e̶t̶w̶o̶r̶k̶s̶:̶
89-
̶ ̶ ̶ ̶ ̶ ̶ ̶ ̶ ̶-̶ ̶a̶p̶p̶w̶r̶i̶t̶e̶
90-
̶ ̶ ̶ ̶ ̶e̶n̶v̶i̶r̶o̶n̶m̶e̶n̶t̶:̶
91-
̶ ̶ ̶ ̶ ̶ ̶ ̶ ̶ ̶-̶ ̶M̶A̶I̶L̶N̶A̶M̶E̶=̶a̶p̶p̶w̶r̶i̶t̶e̶
92-
̶ ̶ ̶ ̶ ̶ ̶ ̶ ̶ ̶-̶ ̶R̶E̶L̶A̶Y̶_̶N̶E̶T̶W̶O̶R̶K̶S̶=̶:̶1̶9̶2̶.̶1̶6̶8̶.̶0̶.̶0̶/̶2̶4̶:̶1̶0̶.̶0̶.̶0̶.̶0̶/̶1̶6̶
93-
</code></pre>
21+
<p>Here's a sample configuration if you're using SendGrid as your SMTP provider. </p>
22+
23+
<div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash">
24+
<pre class="line-numbers">
25+
<code class="prism language-bash" data-prism>
26+
_APP_SMTP_HOST=smtp.sendgrid.net
27+
_APP_SMTP_PORT=587
28+
_APP_SMTP_SECURE=tls
29+
_APP_SMTP_USERNAME=YOUR-SMTP-USERNAME
30+
_APP_SMTP_PASSWORD=YOUR-SMTP-PASSWORD
31+
</code>
32+
</pre>
9433
</div>
9534

9635
<h2>Restart Your Appwrite Server</h2>
9736

98-
<p>After you finished updating and saving your Appwrite docker-compose.yml server you need to restart your Appwrite stack using the following command from your terminal:</p>
37+
<p>Once you've updated your .env file, you need to restart your Appwrite stack using the following command from your terminal:</p>
9938

10039
<div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash">
10140
<pre class="line-numbers"><code class="prism language-bash" data-prism>docker-compose up -d</code></pre>
10241
</div>
10342

104-
<p>That’s it! Go to your Appwrite console again and try to create a new user. If everything went OK, you should get a welcome email in your new user email inbox. As of version 0.5, Appwrite uses its SMTP server to send welcome emails, password recoveries, and user invites. By using a well-configured SMTP server, you can make sure your users enjoy a maximum rate of email deliverability.</p>
43+
<h2>Debugging</h2>
44+
45+
<p>If you are unable to send emails, there is most likely an issue with your integration. The first place to look for possible errors is the <b>Appwrite Emails Worker</b>. You can access the logs of this container using:
46+
47+
<div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash">
48+
<pre class="line-numbers"><code class="prism language-bash" data-prism>docker-compose logs -f appwrite-worker-mails</code></pre>
49+
</div>
50+
</p>
51+
52+
<p>
53+
The next possible source of error is the configuration in your .env file. Make sure that the keys and values are correct and test the credentials by sending a test email using your SMTP providers' SDK or cURL requests.
54+
</p>
55+
56+
<p> Moving on to the next source of error. Some SMTP providers have a concept of <a href="https://help.mailgun.com/hc/en-us/articles/217531258-Authorized-Recipients">authorized recipients</a> in their sandbox (or dev) environments and you can only send emails to recipients in this list. Make sure that the recipient of the email that you're trying to send is a part of this list.</p>
57+
58+
<p>
59+
Another source of error could be that the environment variables have not been set in the appwrite container. You can check this using
60+
<div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash">
61+
<pre class="line-numbers"><code class="prism language-bash" data-prism>docker-compose exec appwrite-worker-mails vars</code></pre>
62+
</div>
63+
If this is the case, you can try rebuilding your appwrite stack using:
64+
<div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash">
65+
<pre class="line-numbers"><code class="prism language-bash" data-prism>docker-compose up -d --build --force-recreate</code></pre>
66+
</div>
67+
68+
</p>
69+
70+
71+
<p>Now you can head over to your Appwrite console, logout from your account and try to recover your password or send invites to other team members from your Appwrite console using your newly configured SMTP provider.</p>

0 commit comments

Comments
 (0)