In the except statement, an email is sent along with the error message. Additionally, you can send emails from any desired line.
- a. Log in with the sender's email ID.
- b. Obtain an app password for sending Google Mail at the following link or google document.
API TEST
from ExceptNotifier import send_gmail_msg
_GMAIL_SENDER_ADDR = '[email protected]'
_GAMIL_RECIPIENT_ADDR = '[email protected]'
_GMAIL_APP_PASSWORD_OF_SENDER = 'xxxx'
subject_msg = "Test Title"
body_msg = "Test Body"
send_gmail_msg(
_GMAIL_SENDER_ADDR,
_GAMIL_RECIPIENT_ADDR,
_GMAIL_APP_PASSWORD_OF_SENDER,
subject_msg,
body_msg)
Notifier
import sys, os
from ExceptNotifier import ExceptMail, SuccessMail, SendMail
sys.excepthook = ExceptMail.__call__
# Define the next two variables optionally when using OpenAI's API.
# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"
# os.environ['_OPEN_AI_API']="sk-xxxxxx"
os.environ['_GAMIL_RECIPIENT_ADDR'] = '[email protected]'
os.environ['_GMAIL_SENDER_ADDR'] = '[email protected]'
os.environ['_GMAIL_APP_PASSWORD_OF_SENDER'] = 'zzzzzz'
try:
main() # Your Code Here
SuccessMail().__call__() # No Exception -> Send Success mail.
except ExceptMail: # Exception -> Send Fail mail.
pass
SendMail().__call__() # When Process Ended -> Any Line mail.
See Example...
import sys, os
from ExceptNotifier import ExceptMail, SuccessMail, SendMail
# Define the next two variables optionally when using OpenAI's API.
# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"
# os.environ['_OPEN_AI_API']="sk-xxxxxx"
os.environ['_GAMIL_RECIPIENT_ADDR'] = '[email protected]'
os.environ['_GMAIL_SENDER_ADDR'] = '[email protected]'
os.environ['_GMAIL_APP_PASSWORD_OF_SENDER'] = 'zzzzzz'
sys.excepthook = ExceptMail.__call__
try:
# 02.Locate your code
print(1/0)
SuccessMail().__call__() # Success Mail
except ExceptMail as e: # Exception Mail
sys.exit()
print(e)
SendMail().__call__() # Put Any Line: Sending mail
Snippet for Python developers...
import sys, os
from ExceptNotifier import ExceptMail, SuccessMail, SendMail
sys.excepthook = ExceptMail.__call__
# Define the next two variables optionally when using OpenAI's API.
# os.environ['_OPEN_AI_MODEL']="gpt-3.5-turbo"
# os.environ['_OPEN_AI_API']="sk-xxxxxx"
os.environ['_GAMIL_RECIPIENT_ADDR'] = '[email protected]'
os.environ['_GMAIL_SENDER_ADDR'] = '[email protected]'
os.environ['_GMAIL_APP_PASSWORD_OF_SENDER'] = 'zzzzzz'
try:
'your code'
SuccessMail().__call__()
except ExceptMail:
pass
SendMail().__call__()