Smarty allows you to send emails via SMTP when certain events occur, such as: sending notifications to customers (about activating tariffs, payment reminders, etc.), alarming in case of accidents (triggers in the monitoring module).
In order to send emails, you need to specify the data for connecting to SMTP server in the Smarty configuration file:
- DEFAULT_FROM_EMAIL — address in the “From” field in sent service emails by default. Data type: string.
- SERVER_EMAIL — must be the same value as in DEFAULT_FROM_EMAIL.
- EMAIL_HOST — SMTP server address. Data type: string.
- EMAIL_PORT — SMTP server port. Data type: int.
- EMAIL_HOST_USER — username. Data type: string.
- EMAIL_HOST_PASSWORD — password. Data type: string.
- EMAIL_USE_TLS — flag, depending on which TLS encryption protocol will be enabled or not. Data type: bool. Default is True.
Setting example:
DEFAULT_FROM_EMAIL = ‘robot@example.com’
SERVER_EMAIL = ‘robot@example.com’
EMAIL_HOST = ‘smtp.example.com’
EMAIL_PORT = 587
EMAIL_HOST_USER = ‘robot@example.com’
EMAIL_HOST_PASSWORD = ‘z272LOCXmZdQ01yK’
EMAIL_USE_TLS = True
Functionality check
In order to debug sending emails, you can use the following script. Run a shell (needs root privileges):
smarty_manage shell —settings=settings.smarty
Replace settings.smarty with your configuration file if it is different.
In the opened shell, execute the script:
from django.core.mail import send_mail
send_mail(«test», «message», None, [«mail@example.com»])
The latter command will send an email to the specified address. If successful, code 1 will be returned.