Sending email in Divio applications¶
Divio does not provide mail services. To send mail from your Django applications, you will need to provide the appropriate configuration.
Django provides email wrappers around Python’s
The following configuration settings can be provided:
- Basic settings
- Authentications settings
- Secure authentication
EMAIL_URL environment variable¶
However, the preferred way to provide these is via an
EMAIL_URL environment variable, so that your local, Test and Live servers can use their own configuration.
EMAIL_URL is the recommended way of combining the settings into a single variable. For
example, suppose you have:
EMAIL_HOST = smtp.example.com EMAIL_PORT = 25 EMAIL_HOST_USER = janeausten EMAIL_HOST_PASSWORD = password
you can instead use:
?tls=True(and use port 587)
?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 environment variables.
Allows you to specify a default
Fromaddress for general automated messages from your website.
Specifies a default
Fromaddress 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 Django documentation has more information.
Once in the shell, launch the Django shell:
python manage.py shell
Import the Django
from django.core.mail import send_mail
and try sending a message:
send_mail( "Welcome to Divio", "It's great!", "firstname.lastname@example.org", ["email@example.com"], fail_silently=False, )
The email settings will be taken from the EMAIL_URL environment variable, but can be overwritten in the shell - for example:
EMAIL_USE_TLS = True