2 min read

How to Configure the Mailservice

Adding a mail service to Directus is very important, without this configured, user's will not receive any emails from Directus including password reset tokens.
How to Configure the Mailservice

Adding a mail service to Directus is very important, without this configured, user's will not receive any emails from Directus including password reset tokens. If you're using the Directus Cloud service, you will already have a mailservice configured. This article will cover some recommended SMTP providers and how you can add the smtp setting to you system.

Once you have your SMTP settings from your provider, edit the env file in your project folder and add the required parameters.

Choose an Email provider

First, you will need an email provider, not Gmail or Yahoo, but an email transport provider that allows you to send hundreds of thousands of email a month. It's worth considering how many emails you intend to send a month. I recommend the following providers which support SMTP.

These have a free tier but check if the monthly volume is enough. If you want to start email marketing, these platforms will grow with you. Moosend in particular has an excellend online builder so you don't need to worry about coding emails.

Once you have an account, obtain the smtp settings and credentials. I recommend you integrate your domain name so you can send emails from your own domain and they get digitally signed so they won't go to spam. Some organisations will have a dedicated SMTP server or Saas, please speak to your IT team for the details.

What not use my own server?

It's very tempting to use your own server for sending emails but this tends to be more hassle than it's worth especially when hosting the software consumes much needed resources away from Directus and any websites running on your server.

These 3rd party email providers will take care of all the security concerns and spam protection with some offering this service for free. So you won't need to set up DKIM keys, SPF verifications, Email Encryptions etc.

Update your Configuration File

Next, you need to edit your .env file using Vim in Linux or a text editor in Windows. It's located within the project folder that Directus was installed into. Use this command on Linux.

vim /path/to/your/project/.env

Near the bottom, you'll see the EMAIL_TRANSPORT setting, change this to smtp. Also make sure the EMAIL_FROM address is supported by your provider. Some will allow you to add your own domain name.

EMAIL_FROM="[email protected]"
EMAIL_TRANSPORT="smtp"

Then add the missing parameters listed below.

EMAIL_SMTP_HOST="smtp.example.com"
EMAIL_SMTP_PORT="587"
EMAIL_SMTP_USER="username"
EMAIL_SMTP_PASSWORD="password"

Save and close this file. For those new to Vim, press ESC to exit out of INSERT mode, then type :wq (colon is required) which will write changes and quit.

Restart Directus

You'll need to restart Directus for that changes to take effect.

Testing the SMTP Service

You can test the email capabilities by going to the login screen and clicking Forgot Password. This will email the address you provide (if it has an account) and you'll see it arrive in your inbox.

Conclusion

Email is a big part of any project. It's the main communication method between your platform and users. You can also use the SMTP service with your website. Some providers have a marketing interface so you can run campaigns. And best of all, they grow with you. If you need to expand, they offer various pricing tiers.

By continuing to use our website, you consent to use essential cookies. We also use optional tracking cookies which help us gather statistics to improve our services. Do you consent to these cookies?

I Consent Do not track