Sending email in Divio Cloud applications¶
Django provides email wrappers around Python’s module.
The following configuration settings can be provided:
- Basic settings
EMAIL_HOST
andEMAIL_PORT
(defaults to25
)- Authentications settings
EMAIL_HOST_USER
and- Secure authentication
EMAIL_USE_TLS
andEMAIL_USE_SSL
However, the preferred way to provide these is via an EMAIL_URL
, so that your local, Test and Live servers can use their own configuration.
The EMAIL_URL
is the recommended way of combining the settings into a single variable. Forexample, suppose you have:
- smtp://janeausten:password@smtp.example.com:25
For:
- SSL, add ?ssl=True (and use port 465)
to the URL. Note that TLS is preferred, and you can’t use both.
The URL is parsed using the dj-email-url library.
Additional Django email settings¶
Some additional email settings are available in Django. These can be provided as environmentvariables.
- Allows you to specify a default
From
address for general automated messages from yourwebsite. SERVER_EMAIL
- Specifies a default
From
address for error messages from your site.
Usage, testing and troubleshooting¶
It’s beyond the scope of this document to discuss usage in detail. The official has more information.
Once in the shell, launch the Django shell:
Import the Django send_mail
function:
- from django.core.mail import send_mail
and try sending a message:
The email settings will be taken from the EMAIL_URL environment variable, butcan be overwritten in the shell - for example: