Sometimes you need your project to be able to send email messages.

For example, you may have a form on the site (using, say, Aldryn Forms) that as well as saving responses to the database should email them to the site managers.

Once you have configured the form in the website to send responses appropriately, you also need to configure the Django project to handle the email.

The correct way to do this is by setting an environment variable in the project.

Variables

EMAIL_URL

Divio Cloud sites make use of an EMAIL_URL variable, that combines the SMTP settings you need. For example if they are:

  • server: smtp.example.com 
  • username: janeausten 
  • password: 45vFes7Trw 
  • port: 587 

then your EMAIL_URL would be:

smtp://janeausten:45vFes7Trw@smtp.example.com:587

If the service requires that you use TLS, you can use smtps://, or add ?tls=True to the URL.

If you need to use SSL, add ?ssl=True to the URL, for example:

smtp://janeausten:45vFes7Trw@smtp.example.com:587/?ssl=True

The URL is parsed using the dj-email-url library: https://github.com/migonzalvar/dj-email-url.

You should specify an EMAIL_URL for both Test and Live servers, unless you have a good reason not to. The two EMAIL_URLs can be different.

DEFAULT_FROM_EMAIL

The Django DEFAULT_FROM_EMAIL setting allows you to specify a default From address for general automated messages from your website. You can provide this as an environment variable.

SERVER_EMAIL

SERVER_EMAIL specifies a default From address for error messages from your site.

You can provide this as an environment variable.

Setting environment variables

See Setup environment variables for your servers  for more details, but in brief:

Using the Control Panel

Add environment variables such as EMAIL_URL to a project using the Control Panel's Environment Variables page.

Locally

Place the variables in your project's .env-local file.

Did this answer your question?