BUG: Empty email being generated
rderooy opened this issue · 0 comments
Describe the bug
I'm having a problem with the MultiEmailHandler, that two emails are being sent. One valid email and one empty email. The empty email will still have the subject line, but the min_level_name and max_level_name will be set to "NOTSET".
I tried to manually flush or close the handler before the script ends, but that just makes it worse and causes even more empty emails.
To Reproduce
See below for testcase
One email will be valid, a second email will have a subject of "email test: NOTSET - NOTSET"
Expected behavior
A single email to be generated for the run of the script.
Email provider:
- Email service: private
- Application to view the email: not relevant
Environment (please complete the following information if relevant):
- OS: Linux
- Python version: 3.11
- Red Mail version: 0.6.0
Additional context
Add any other context about the problem here.
#!/bin/python3
""" test MultiEmailHandler """
import logging.handlers
from redmail import MultiEmailHandler
# Create a custom logger
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.INFO)
# Create email log handler
SMTP_SERVER = "email.server"
SENDER_EMAIL = "sender.email.address@server"
RECEIVER_EMAIL = ["receiver.email.address@server"]
SUBJECT="email test: {min_level_name} - {max_level_name}"
E_HANDLER = MultiEmailHandler(capacity=1024, **{
'host': SMTP_SERVER,
'port': 0,
'sender': SENDER_EMAIL,
'subject': SUBJECT,
'receivers': RECEIVER_EMAIL,
'text': """Logging level:
{% for record in records %}
Level name: {{ record.levelname }}
Message: {{ record.msg }}
{% endfor %}
""",
'html': """
<ul>
{% for record in records %}
<li>Level name: {{ record.levelname }}</li>
<li>Message: {{ record.msg }}</li>
{% endfor %}
</ul>
"""}
)
E_HANDLER.setLevel(logging.INFO)
LOG.addHandler(E_HANDLER)
LOG.debug("Testing debug")
LOG.info("Testing info")
LOG.warning("Testing warning")
LOG.error("Testing error")