Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Empty email being generated #83

Open
rderooy opened this issue Aug 16, 2023 · 0 comments
Open

BUG: Empty email being generated #83

rderooy opened this issue Aug 16, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@rderooy
Copy link

rderooy commented Aug 16, 2023

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")
@rderooy rderooy added the bug Something isn't working label Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant