digitalec / deemon

Monitor specified artists for new releases
GNU General Public License v3.0
177 stars 15 forks source link

Email notifications broken since 2.21? #109

Closed philmichel closed 6 months ago

philmichel commented 7 months ago

Hi there,

Thank you for your dedication to this project <3

Is it possible that email notifications are broken since 2.21? I noticed no longer getting emails since around April 4th.

What is interesting is that the test email functionality works perfectly, so I don't believe my email setup is broken (and it hasn't changed).

What I have noticed is that there is no longer any confirmation that emails are sent in the logs since 2.21. It is almost as if deemon is crashing right when it tries to send emails. To illustrate, here is what a successful run with emails sent looked like as of April 4th:

2024-04-04 11:01:13 [INFO] deemon.utils.performance: Operation completed in 00:01:09
2024-04-04 11:01:13 [INFO] deemon.cmd.refresh: Database is up-to-date.
2024-04-04 11:01:13 [DEBUG] deemon.core.notifier: Sending notification for [{'release_date': '2024-03-08', 'releases': REDACTED', 'track_num': '1', 'record_type': 'single'}]}] release(s)
2024-04-04 11:01:13 [DEBUG] deemon.core.notifier: Sending notification email
2024-04-04 11:01:13 [DEBUG] deemon.core.notifier: Using server: smtp.gmail.com:587
2024-04-04 11:01:15 [DEBUG] deemon.core.notifier: Email notification has been sent

whereas nowadays I get

2024-04-27 11:02:29 [INFO] deemon.utils.performance: Operation completed in 00:02:08
2024-04-27 11:02:29 [INFO] deemon.cmd.refresh: Database is up-to-date.
2024-04-27 11:02:29 [DEBUG] deemon.core.notifier: Sending notification for [{'release_date': '2024-04-25', 'releases': REDACTED, 'track_num': '139', 'record_type': 'album'}]}] release(s)

It seems like the email send isn't actually getting triggered or perhaps it crashes before it can complete?

Are there any new options that were added in 2.21 and later that are required to enable email notifications?

Many thanks!

philmichel commented 7 months ago

I did some more debugging and have traced it to deemon/core/notifier.py, line 131. The move from pkg_resources to pkgutil in this commit seems to be the problem.

Full traceback below. Looking at it, it seems to be trying to open a file with the entire email contents as the name? Is the syntax of the new pkgutil lib just different and perhaps it needs to be adjusted?

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/app/deemon/__main__.py", line 9, in <module>
    main()
  File "/app/deemon/__main__.py", line 5, in main
    cli.run()
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/app/deemon/cli.py", line 293, in refresh_command
    refresh.run()
  File "/app/deemon/cmd/refresh.py", line 292, in run
    notification.send()
  File "/app/deemon/core/notifier.py", line 39, in send
    body = self.html_message()
  File "/app/deemon/core/notifier.py", line 77, in html_message
    html_body = MIMEText(self.html_new_releases(), 'html')
  File "/app/deemon/core/notifier.py", line 191, in html_new_releases
    with open(index, 'r') as f:
OSError: [Errno 36] File name too long: b'<!DOCTYPE html>\n<html lang="en">\n  <head>\n    <meta charset="UTF-8">\n    <meta name="viewport" content="width=device-width, initial-scale=1.0">\n    <meta name="color-scheme" content="light dark">\n    <title>deemon</title>\n    <style>\n    \t@import url(\'https://fonts.googleapis.com/css2?family=Baloo+Tammudu+2&display=swap\');\n    \t\n    \t:root {\n    \t\t--bg: #c0c0c0;\n    \t\t--text: #708090;\n    \t\t--banner-text: #404040;\n    \t\t--card-bg: #f0f0f0;\n    \t\t--date-badge-bg: #6106e5;\n    \t\t--date-badge-text: #6106e5;\n    \t\t--albuminfo-a: #70af71;\n    \t\t--album-footer: #e0e0e0;\n    \t\t--drop-shadow: #808080;\n    \t}\n    \t\n    \tbody {\n    \t\tfont-family: \'Baloo Tammudu 2\', sans-serif;\n    \t\tbackground: var(--bg);\n            margin:0;\n    \t}\n    \t\n\t\t@media (prefers-color-scheme: dark) {\n\t\t\t:root {\n\t\t\t\t--bg: #000000;\n\t\t\t\t--text: #ffffff;\n    \t\t\t--banner-text: #ffffff;\n\t\t\t\t--card-bg: #000000;\n    \t\t\t--date-badge-bg: #ffffff;\n    \t\t\t--date-badge-text: #ffffff;\n    \t\t\t--albuminfo-a: #70af71;\n    \t\t\t--album-footer: #303030;\n    \t\t\t--drop-shadow: #000000;\n\t\t\t}\n\t\t}\n    \t\n    \ta {\n    \t\ttext-decoration: none;\n    \t\tcolor: var(--albuminfo-a);\n    \t}\n    \t\n    \ta:hover {\n    \t\ttext-decoration: underline;\n    \t}\n    \t\n    \t.container {\n    \t\tposition: relative;\n    \t\tfont-family: sans-serif;\n    \t\tbackground: var(--card-bg);\n    \t}\n    \t\n    \t.album.container {\n    \t\tdisplay: flex;\n    \t\tflex-wrap: wrap;\n    \t\tjustify-content: left;\n    \t\talign-items: left;\n    \t}\n    \t\n    \t.album {\n    \t\twidth:100%;\n    \t\tbackground: var(--card-bg);\n    \t\tbox-sizing: border-box;\n    \t\tpadding: 10px;\n    \t}\n    \t\n    \t.album.header {\n    \t\tborder-top-left-radius: 17px;\n    \t\tborder-top-right-radius: 17px;\n    \t\tbackground: var(--card-bg);\n    \t\theight: 150px;\n    \t\tdisplay: flex;\n    \t\tjustify-content: center;\n    \t\talign-items: center;\n    \t\tcolor: #6106e5;\n    \t\tpadding-top: 35px;\n    \t\tfont-family: \'Baloo Tammudu 2\', sans-serif;\n    \t\tfont-weight: bold;\n    \t\tfont-size: 2.5em;\n    \t}\n    \t\n    \t.album.updates {\n    \t\tdisplay: flex;\n    \t\tjustify-content: center;\n    \t\talign-items: center;\n    \t\tbackground: #70af71;\n    \t\tfont-family: sans-serif;\n    \t\tfont-size: 1em;\n    \t\tcolor: #fff;\n    \t\tmargin-bottom: 20px;\n    \t}\n    \t\n    \t.album.new-release-banner {\n    \t\tdisplay: flex;\n    \t\tjustify-content: center;\n    \t\talign-items: center;\n    \t\tfont-size: 1.25em;\n    \t\tmargin-bottom: -10px;\n    \t\tcolor: var(--banner-text);\n    \t}\n    \t\n    \t.album.body {\n    \t\tflex: 0 0 25%;\n    \t\tmin-width: 350px;\n    \t\tcolor: var(--text);\n    \t\tpadding: 0px;\n    \t\tpadding-left: 10px;\n    \t\tfont-size: 0.9em;\n    \t\tdisplay: flex;\n    \t\tmargin-bottom: 30px;\n    \t}\n    \t\n    \t.album.date {\n    \t\tmargin-top: 40px;\n    \t\tmargin-bottom: 30px;\n    \t}\n    \t\n    \t.album.date.badge {\n    \t\tcolor: var(--date-badge-text);\n    \t\tbackground: none;\n    \t\tborder-radius: 7px;\n    \t\tborder: 1px solid var(--date-badge-bg);\n    \t\ttext-shadow: none;\n    \t\tfont-size: 1em;\n    \t\tfont-family: sans-serif;\n    \t}\n    \t\n    \t.album.subheader {\n    \t\tdisplay: flex;\n    \t\tjustify-content: center;\n    \t\talign-items: center;\n    \t}\n    \t\n    \t.footerarea {\n    \t\tdisplay: flex;\n    \t\tjustify-content: center;\n    \t\talign-items: center;\n    \t\theight: 50px;\n    \t\tcolor: #a0a0a0;\n    \t}\n    \t\n    \t.album.support {\n    \t\tfont-size: 0.8em;\n    \t\tline-height: 1em;\n    \t}\n    \t\n    \t.album.footer {\n    \t\tborder-bottom-left-radius: 7px;\n    \t\tborder-bottom-right-radius: 7px;\n    \t\tfont-family: monospace;\n            font-size: 0.60em;\n    \t\tbackground: var(--album-footer);\n    \t}\n    \t\n    \t.albumtitle {\n    \t\tmargin-top: 5px;\n    \t\tfont-weight: bold;\n    \t}\n    \t\n    \t.artistname {\n    \t\tfont-style:italic;\n    \t\tpadding-bottom:10px;\n    \t}\n    \t\n    \t.albuminfo {\n    \t}\n    \t\n    \t.albuminfo a {\n    \t\tcolor: var(--albuminfo-a);\n    \t}\n    \t\n    \t.albumart {\n    \t\tfloat: left;\n    \t\tmargin-right: 20px;\n    \t}\n    \t\n    \t.albumart img {\n    \t\tborder-radius: 7px;\n    \t\tfilter: drop-shadow(0.1rem 0.1rem 0.2rem var(--drop-shadow));\n    \t\twidth: 150px;\n    \t\theight: 150px;\n    \t}\n    </style>\n  </head>\n  <body>\n\t<div class="container">\n\t\t<div class="album header">\n\t\t\tdeemon\n\t\t</div>\n\t\t<div class="album updates" style="{VIEW_UPDATE_MESSAGE}">\n\t\t\t{UPDATE_MESSAGE}\n\t\t</div>\n\t\t<div class="album new-release-banner">\n\t\t\t{NEW_RELEASE_COUNT} new release(s) were found!\n\t\t</div>\n\t\t<!---- START ALBUM LIST HERE ---->\n\t\t<div class="album container">\n\t\t\t{NEW_RELEASE_LIST}\n\t\t</div>\n\t\t<!---- END ALBUM LIST HERE ---->\n\t\t<div class="album support footerarea">\n\t\t\t<span style="white-space: pre-line;">\n\t\t\t\tOpen an issue on <a href="https://github.com/digitalec/deemon">GitHub</a> or join us on <a href="https://discord.gg/KzNCG2tkvn">Discord</a>\n\t\t\t</span>\n\t\t</div>\n\t\t<div class="album footer footerarea">\n\t\t\t{DEEMON_VER} | {PY_VER} | {SYS_VER}\n\t\t</div>\n\t</div>\n  </body>\n</html>'
digitalec commented 7 months ago

Sorry, I thought I replied here. The move to pkgutil changes things because it handles the open() of the file. The with open(… should be removed now. I’ll patch this up hopefully this weekend! Thanks.

digitalec commented 6 months ago

This has been fixed in 2.21.2 and is available now.