How to send myself an email notification when a suds job is done?

9k views Asked by At

I'm learning to use suds in a python script to send SQL queries to a database. I'd like to able to send myself an email when the query job is finished (it has a job ID so I'm able to check its status). How do I do that?

3

There are 3 answers

1
Jacob Corrigon On

This is how you send an email via python just fill in the blanks and input it to your code:

import smtplib

content = ("Content to send")

mail = smtplib.SMTP('smtp.gmail.com',587)

mail.ehlo()

mail.starttls()

mail.login('[email protected]','123your_password')

mail.sendmail('[email protected]','[email protected]',content) 

mail.close()

print("Sent")

(you dont have to use gmail as most addresses will still work through the gmail smtp)

0
W. Ding On

I just wrote a Python decorator for this purpose. You can realize it in one line.

https://github.com/Wenzhi-Ding/py_reminder

from py_reminder import monitor

@monitor('SQL Query of xxx')
def query(sql):
    ...send your query...

query()

Once this function finishes / or is caught an error, you will get an email notification with some brief information.

0
xurei On

If email is not required, you can also send chat messages to yourself.

Two projects achieving this :