Issue with notifiers
VanadisOdr opened this issue · 15 comments
Hi there!
Could you help me please with my problem?
I need send a notifications to @mail.ru, but it doesnt working, what the problem?
import notifiers
from dotenv import load_dotenv
import os
from loguru import logger
load_dotenv()
params_mail = {
"from": os.getenv('MAIL2'),
"to": os.getenv('MAIL'),
"host": "smtp.mail.ru",
"port": 578,
"subject": "loguru",
"username": os.getenv('MAIL2'),
"password": os.getenv('PASSWORD')
}
notifiers.get_notifier("email").notify(message="The application is running!", **params_mail)
from notifiers.logging import NotificationHandler
handler = NotificationHandler(provider='email', defaults=params_mail)
logger.add(handler, level="ERROR")
its also doesnt work by itself (not involving Loguru)
when you send a message using the email provider, not via the logging handler, does it work?
when you send a message using the email provider, not via the logging handler, does it work?
Sure
its also doesnt work by itself (not involving Loguru)
can you show how you use it? and any error if avaialble
from loguru import logger
import notifiers
from dotenv import load_dotenv
import os
logger.add('debug.log', format='{time} {level} {message}',
level='DEBUG', rotation='10:00', compression='zip')
@logger.catch(Exception)
def sym(num1, num2):
return num1 / num2
try:
sym(1, 0)
except Exception as err:
logger.error(err)
load_dotenv()
params_mail = {
"from": os.getenv('MAIL2'),
"to": os.getenv('MAIL'),
"host": "smtp.mail.ru",
"port": 25,
"subject": "loguru",
"username": os.getenv('MAIL2'),
"password": os.getenv('PASSWORD')
}
Send a single notification
notifiers.get_notifier("email").notify(message="The application is running!", **params_mail)
from notifiers.logging import NotificationHandler
handler = NotificationHandler(provider='email', defaults=params_mail)
logger.add(handler, level="ERROR")
thereisnt any errors, just finish :(
Please add raise_on_errors
:
notifiers.get_notifier("email").notify(message="The application is running!", raise_on_errors=True, **params_mail)
2023-06-20 16:37:24.186 | ERROR | main::18 - An error has been caught in function '', process 'MainProcess' (17564), thread 'MainThread' (12568):
Traceback (most recent call last):
File "C:\Users\olegg\PycharmProjects\sendlogmail\main.py", line 18, in
sym(1, 0)
└ <function sym at 0x0000020FE7B58540>
File "C:\Users\olegg\PycharmProjects\sendlogmail\main.py", line 14, in sym
return num1 / num2
│ └ 0
└ 1
ZeroDivisionError: division by zero
Traceback (most recent call last):
File "C:\Users\olegg\PycharmProjects\sendlogmail\main.py", line 35, in
notifiers.get_notifier("email").notify(message="The application is running!", raise_on_errors=True, **params_mail)
File "C:\Users\olegg\PycharmProjects\sendlogmail\venv\Lib\site-packages\notifiers\core.py", line 306, in notify
rsp.raise_on_errors()
File "C:\Users\olegg\PycharmProjects\sendlogmail\venv\Lib\site-packages\notifiers\core.py", line 60, in raise_on_errors
raise NotificationError(
notifiers.exceptions.NotificationError: Notification errors: SMTP AUTH extension not supported by server.
Process finished with exit code 1
I also want to note that the smtp port is 465, but in the parameters (params mail) it indicates the port for tсp - 25. If I set 465, then the program does not end, and with 25 a similar error (example above)
UPD: port 465 - error
notifiers.exceptions.NotificationError: Notification errors: Connection unexpectedly closed
This is entirely SMTP related, not notifiers.
You probably need to set port to 465 and enable SSL, and TLS
try this:
params_mail = {
"from": os.getenv('MAIL2'),
"to": os.getenv('MAIL'),
"host": "smtp.mail.ru",
"port": 465,
"ssl": True,
"tls": True,
"subject": "loguru",
"username": os.getenv('MAIL2'),
"password": os.getenv('PASSWORD')
}
notifiers.get_notifier("email").notify(message="The application is running!", raise_on_errors=True, **params_mail)
closing this as this is not a notifiers issue. good luck!
This is entirely SMTP related, not notifiers. You probably need to set port to 465 and enable SSL, and TLS try this:
params_mail = { "from": os.getenv('MAIL2'), "to": os.getenv('MAIL'), "host": "smtp.mail.ru", "port": 465, "ssl": True, "tls": True, "subject": "loguru", "username": os.getenv('MAIL2'), "password": os.getenv('PASSWORD') } notifiers.get_notifier("email").notify(message="The application is running!", raise_on_errors=True, **params_mail)
TY a million, its works for me
Could you pls say me how to send a debug file in notifier? (Attached file to email)
notifiers.get_notifier("email").notify(message='The app is running!',attachments=['/sendlogmail/debug.log'], raise_on_errors=True, **params_mail)
:)