diff --git a/api/libretime_api/settings/_schema.py b/api/libretime_api/settings/_schema.py index 5b339f775..e9a5ffdc2 100644 --- a/api/libretime_api/settings/_schema.py +++ b/api/libretime_api/settings/_schema.py @@ -1,3 +1,5 @@ +from typing import Literal, Optional + from libretime_shared.config import ( BaseConfig, DatabaseConfig, @@ -5,6 +7,20 @@ from libretime_shared.config import ( RabbitMQConfig, StorageConfig, ) +from pydantic import BaseModel + + +class EmailConfig(BaseModel): + from_email: str = "no-reply@libretime.org" + + host: str = "localhost" + port: int = 25 + user: str = "" + password: str = "" + encryption: Optional[Literal["ssl/tls", "starttls"]] = None + timeout: Optional[int] = None + key_file: Optional[str] = None + cert_file: Optional[str] = None class Config(BaseConfig): @@ -12,3 +28,4 @@ class Config(BaseConfig): database: DatabaseConfig = DatabaseConfig() rabbitmq: RabbitMQConfig = RabbitMQConfig() storage: StorageConfig = StorageConfig() + email: EmailConfig = EmailConfig() diff --git a/api/libretime_api/settings/prod.py b/api/libretime_api/settings/prod.py index 9afbdf067..2d8e0741c 100644 --- a/api/libretime_api/settings/prod.py +++ b/api/libretime_api/settings/prod.py @@ -73,3 +73,20 @@ LANGUAGE_CODE = "en-us" TIME_ZONE = "UTC" USE_I18N = True USE_TZ = True + +# Email +# https://docs.djangoproject.com/en/4.2/topics/email/ + +EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" + +EMAIL_HOST = CONFIG.email.host +EMAIL_PORT = CONFIG.email.port +EMAIL_HOST_USER = CONFIG.email.user +EMAIL_HOST_PASSWORD = CONFIG.email.password +EMAIL_USE_SSL = CONFIG.email.encryption == "ssl/tls" # implicit +EMAIL_USE_TLS = CONFIG.email.encryption == "starttls" # explicit +EMAIL_TIMEOUT = CONFIG.email.timeout +EMAIL_SSL_KEYFILE = CONFIG.email.key_file +EMAIL_SSL_CERTFILE = CONFIG.email.cert_file + +DEFAULT_FROM_EMAIL = CONFIG.email.from_email diff --git a/api/libretime_api/settings/testing.py b/api/libretime_api/settings/testing.py index 94e4a7a97..ed83d5c4d 100644 --- a/api/libretime_api/settings/testing.py +++ b/api/libretime_api/settings/testing.py @@ -18,6 +18,7 @@ from .prod import ( DATABASES, DEBUG, DEFAULT_AUTO_FIELD, + DEFAULT_FROM_EMAIL, INSTALLED_APPS, LANGUAGE_CODE, LOGGING, @@ -34,6 +35,11 @@ from .prod import ( WSGI_APPLICATION, ) +# Email +# https://docs.djangoproject.com/en/4.2/topics/email/ + +EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" + # Testing # https://docs.djangoproject.com/en/3.2/ref/settings/#test-runner diff --git a/docker/config.template.yml b/docker/config.template.yml index 6f9938291..8d9f4b34d 100644 --- a/docker/config.template.yml +++ b/docker/config.template.yml @@ -70,6 +70,35 @@ rabbitmq: # > default is libretime password: ${RABBITMQ_DEFAULT_PASS} +email: + # Sender email address to use when sending emails. + # > default is no-reply@libretime.org + from_address: no-reply@libretime.org + + # The hostname of the SMTP server. + # > default is localhost + host: localhost + # The port of the SMTP server. + # > default is 25 + port: 25 + # Whether to use an insecure connection, an SSL/TLS (implicit) connection (generally + # on port 465) or a STARTTLS (explicit) connection (generally on port 587) when + # talking to the SMTP server. + # > must be one of (ssl/tls, starttls) + encryption: + # The username to use for the SMTP server. + # > default is "" + user: "" + # The password to use for the SMTP server. + # > default is "" + password: "" + # Timeout in seconds for blocking operations like the connection attempt. + timeout: + # The path to a PEM-formatted certificate chain file to use for the connection. + cert_file: + # The path to a PEM-formatted private key file to use for the connection. + key_file: + playout: # Liquidsoap connection host. # > default is localhost diff --git a/docker/config.yml b/docker/config.yml index b6a11e3d5..ef2b8059e 100644 --- a/docker/config.yml +++ b/docker/config.yml @@ -70,6 +70,35 @@ rabbitmq: # > default is libretime password: libretime +email: + # Sender email address to use when sending emails. + # > default is no-reply@libretime.org + from_address: no-reply@libretime.org + + # The hostname of the SMTP server. + # > default is localhost + host: localhost + # The port of the SMTP server. + # > default is 25 + port: 25 + # Whether to use an insecure connection, an SSL/TLS (implicit) connection (generally + # on port 465) or a STARTTLS (explicit) connection (generally on port 587) when + # talking to the SMTP server. + # > must be one of (ssl/tls, starttls) + encryption: + # The username to use for the SMTP server. + # > default is "" + user: "" + # The password to use for the SMTP server. + # > default is "" + password: "" + # Timeout in seconds for blocking operations like the connection attempt. + timeout: + # The path to a PEM-formatted certificate chain file to use for the connection. + cert_file: + # The path to a PEM-formatted private key file to use for the connection. + key_file: + playout: # Liquidsoap connection host. # > default is localhost diff --git a/docker/example/config.yml b/docker/example/config.yml index 0c601ea5f..cb183fc33 100644 --- a/docker/example/config.yml +++ b/docker/example/config.yml @@ -70,6 +70,35 @@ rabbitmq: # > default is libretime password: libretime +email: + # Sender email address to use when sending emails. + # > default is no-reply@libretime.org + from_address: no-reply@libretime.org + + # The hostname of the SMTP server. + # > default is localhost + host: localhost + # The port of the SMTP server. + # > default is 25 + port: 25 + # Whether to use an insecure connection, an SSL/TLS (implicit) connection (generally + # on port 465) or a STARTTLS (explicit) connection (generally on port 587) when + # talking to the SMTP server. + # > must be one of (ssl/tls, starttls) + encryption: + # The username to use for the SMTP server. + # > default is "" + user: "" + # The password to use for the SMTP server. + # > default is "" + password: "" + # Timeout in seconds for blocking operations like the connection attempt. + timeout: + # The path to a PEM-formatted certificate chain file to use for the connection. + cert_file: + # The path to a PEM-formatted private key file to use for the connection. + key_file: + playout: # Liquidsoap connection host. # > default is localhost diff --git a/docs/admin-manual/configuration.md b/docs/admin-manual/configuration.md index d3273de3b..0ca40661e 100644 --- a/docs/admin-manual/configuration.md +++ b/docs/admin-manual/configuration.md @@ -151,6 +151,65 @@ rabbitmq: password: "some_random_generated_secret!" ``` +## Email + +The `email` section configure a SMTP server used to send emails. + +```yml +email: + # Sender email address to use when sending emails. + # > default is no-reply@libretime.org + from_address: no-reply@libretime.org + + # The hostname of the SMTP server. + # > default is localhost + host: localhost + # The port of the SMTP server. + # > default is 25 + port: 25 + # Whether to use an insecure connection, an SSL/TLS (implicit) connection (generally + # on port 465) or a STARTTLS (explicit) connection (generally on port 587) when + # talking to the SMTP server. + # > must be one of (ssl/tls, starttls) + encryption: + # The username to use for the SMTP server. + # > default is "" + user: "" + # The password to use for the SMTP server. + # > default is "" + password: "" + # Timeout in seconds for blocking operations like the connection attempt. + timeout: + # The path to a PEM-formatted certificate chain file to use for the connection. + cert_file: + # The path to a PEM-formatted private key file to use for the connection. + key_file: +``` + +:::info + +Below are 2 common email configuration example: + +```yml +email: + host: mail.gandi.net + port: 587 + encryption: starttls + user: some_user + password: some_password! +``` + +```yml +email: + host: mail.gandi.net + port: 465 + encryption: ssl/tls + user: some_user + password: some_password! +``` + +::: + ## Playout The `playout` section configure anything related to the playout service. diff --git a/installer/config.yml b/installer/config.yml index 9f08555a2..ea059cee2 100644 --- a/installer/config.yml +++ b/installer/config.yml @@ -70,6 +70,35 @@ rabbitmq: # > default is libretime password: libretime +email: + # Sender email address to use when sending emails. + # > default is no-reply@libretime.org + from_address: no-reply@libretime.org + + # The hostname of the SMTP server. + # > default is localhost + host: localhost + # The port of the SMTP server. + # > default is 25 + port: 25 + # Whether to use an insecure connection, an SSL/TLS (implicit) connection (generally + # on port 465) or a STARTTLS (explicit) connection (generally on port 587) when + # talking to the SMTP server. + # > must be one of (ssl/tls, starttls) + encryption: + # The username to use for the SMTP server. + # > default is "" + user: "" + # The password to use for the SMTP server. + # > default is "" + password: "" + # Timeout in seconds for blocking operations like the connection attempt. + timeout: + # The path to a PEM-formatted certificate chain file to use for the connection. + cert_file: + # The path to a PEM-formatted private key file to use for the connection. + key_file: + playout: # Liquidsoap connection host. # > default is localhost diff --git a/legacy/application/configs/conf.php b/legacy/application/configs/conf.php index ed0e781c8..f21e471a4 100644 --- a/legacy/application/configs/conf.php +++ b/legacy/application/configs/conf.php @@ -65,6 +65,11 @@ class Schema implements ConfigurationInterface /**/->scalarNode('password')->defaultValue('libretime')->end() ->end()->end() + // Email schema + ->arrayNode('email') + /**/->ignoreExtraKeys() + ->end() + // Storage schema ->arrayNode('storage')->addDefaultsIfNotSet()->children() /**/->scalarNode('path')->defaultValue('/srv/libretime/')