Commit b48b9bb9 authored by Robert's avatar Robert

Log errors via logger

parent 328b614c
......@@ -2,6 +2,7 @@ import asyncio
import email.parser
import email.policy
import functools
import logging
import random
import signal
import smtplib
......@@ -17,6 +18,8 @@ from django.conf import settings
from features.contributions.signals import (ContributionMailProcessor, MailProcessingFailure,
logger = logging.getLogger(__name__)
# TODO: the error mail target should be taken from the settings?
# internal error mails are sent to the postmaster
......@@ -30,7 +33,10 @@ class Command(
def handle(self, host=None, port=None, **options):
def message_writer(text, style=None):
if style ==
success_writer = functools.partial(message_writer,
error_writer = functools.partial(message_writer,
lmtp_daemon = ContributionLMTPD(success_writer, error_writer)
......@@ -50,7 +56,7 @@ class ContributionLMTPD:
self._success_writer = success_writer
if error_writer is None:
self._error_writer = functools.partial(print, file=sys.stderr)
self._error_writer = functools.partial(logger.error)
self._error_writer = error_writer
processor = ContributionMailProcessor(settings.STADTGESTALTEN_BOT_EMAIL,
......@@ -144,7 +150,7 @@ class AsyncLMTPClient:
failed_recipients = tuple(failures.keys())
except SMTPRecipientsRefused as exc:
if not hide_error_messages:
print('Failed to submit message: {}'.format(exc), file=sys.stderr)
logger.error('Failed to submit message: {}'.format(exc))
# all deliveries failed
failed_recipients = recipients
await self.smtp_client.quit()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment