Browse Source

Rename SMTP_* configuration variables to MAIL_*

The new configuration variables now match the general convention for
these parameters.
pull/49/head
Reinhard Müller 3 weeks ago
parent
commit
77089768be
6 changed files with 20 additions and 18 deletions
  1. 2
    2
      doc/configure.md
  2. 2
    2
      docker-compose.dev.yml
  3. 1
    1
      docker-compose.yml
  4. 6
    4
      fsfe_forms/app.py
  5. 4
    4
      fsfe_forms/common/config.py
  6. 5
    5
      fsfe_forms/email.py

+ 2
- 2
doc/configure.md View File

@@ -45,13 +45,13 @@ The TCP port to listen on.

## Email settings

### `SMTP_HOST` and `SMTP_PORT`
### `MAIL_SERVER` and `MAIL_PORT`

The SMTP server and port to use for sending out all kinds of emails. Defaults
to `localhost` and `25`.


### `SMTP_USERNAME` and `SMTP_PASSWORD`
### `MAIL_USERNAME` and `MAIL_PASSWORD`

The credentials for the SMTP server. Only needed if the SMTP server requires
authentication.

+ 2
- 2
docker-compose.dev.yml View File

@@ -22,8 +22,8 @@ services:
ports:
- "8080:8080"
environment:
"SMTP_HOST": "forms-fakesmtp"
"SMTP_PORT": "1025"
"MAIL_SERVER": "forms-fakesmtp"
"MAIL_PORT": "1025"
"LOG_EMAIL_FROM": "contact@fsfe.org"
"LOG_EMAIL_TO": "contact@fsfe.org"


+ 1
- 1
docker-compose.yml View File

@@ -40,7 +40,7 @@ services:
LETSENCRYPT_HOST: "forms.fsfe.org"
LETSENCRYPT_EMAIL: "contact@fsfe.org"
RATELIMIT_DEFAULT: "1 per second, 5 per minute, 20 per hour"
SMTP_HOST: "mail.fsfe.org"
MAIL_SERVER: "mail.fsfe.org"
LOG_EMAIL_FROM: "contact@fsfe.org"
LOG_EMAIL_TO: "contact@fsfe.org"
REDIS_HOST: "forms-redis"

+ 6
- 4
fsfe_forms/app.py View File

@@ -59,14 +59,16 @@ def create_app(testing=False):

# Add a log handler which forwards errors by email
if not (app.debug or app.testing): # pragma: no cover
if app.config['SMTP_USERNAME'] is not None:
if app.config['MAIL_USERNAME'] is not None:
credentials = (
app.config['SMTP_USERNAME'],
app.config['SMTP_PASSWORD'])
app.config['MAIL_USERNAME'],
app.config['MAIL_PASSWORD'])
else:
credentials = None
handler = SMTPHandler(
mailhost=app.config['SMTP_HOST'],
mailhost=(
app.config['MAIL_SERVER'],
app.config['MAIL_PORT']),
fromaddr=app.config['LOG_EMAIL_FROM'],
toaddrs=[app.config['LOG_EMAIL_TO']],
subject="Log message from fsfe-forms",

+ 4
- 4
fsfe_forms/common/config.py View File

@@ -2,10 +2,10 @@ import os

RATELIMIT_DEFAULT = os.environ.get('RATELIMIT_DEFAULT')

SMTP_HOST = os.environ.get('SMTP_HOST', 'localhost')
SMTP_PORT = int(os.environ.get('SMTP_PORT', 25))
SMTP_USERNAME = os.environ.get('SMTP_USERNAME')
SMTP_PASSWORD = os.environ.get('SMTP_PASSWORD')
MAIL_SERVER = os.environ.get('MAIL_SERVER', 'localhost')
MAIL_PORT = int(os.environ.get('MAIL_PORT', 25))
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')

LOG_EMAIL_FROM = os.environ.get('LOG_EMAIL_FROM')
LOG_EMAIL_TO = os.environ.get('LOG_EMAIL_TO')

+ 5
- 5
fsfe_forms/email.py View File

@@ -85,12 +85,12 @@ def send_email(template: str, lang: Optional[str] = None, **kwargs):
else:
# Send out the message
with smtplib.SMTP(
host=current_app.config['SMTP_HOST'],
port=current_app.config['SMTP_PORT']) as smtp:
if current_app.config['SMTP_USERNAME']:
host=current_app.config['MAIL_SERVER'],
port=current_app.config['MAIL_PORT']) as smtp:
if current_app.config['MAIL_USERNAME']:
smtp.login(
user=current_app.config['SMTP_USERNAME'],
password=current_app.config['SMTP_PASSWORD'])
user=current_app.config['MAIL_USERNAME'],
password=current_app.config['MAIL_PASSWORD'])
smtp.send_message(message)

return message

Loading…
Cancel
Save