Skip to content

Instantly share code, notes, and snippets.

@walshbr
Last active August 24, 2016 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walshbr/700272d64f328c97075f7bda68a2db88 to your computer and use it in GitHub Desktop.
Save walshbr/700272d64f328c97075f7bda68a2db88 to your computer and use it in GitHub Desktop.
Send yourself a notification when a long script finishes. Requires a gmail account for line 25-6. Adaptation of http://stackoverflow.com/questions/26981591/how-to-send-myself-an-email-notification-when-a-suds-job-is-done
# stick in the root of your directory, then you can import it as a package to be added to the end of a long process.
# Be sure to add notification.py to your .gitignore file to prevent accidentally sharing sensitive personal information.
# =====
# In file that takes forever to run
# At top of file
import notification
# As last line before file end
notification.email_notification_on_completion()
# =====
# IMPORTANT
# to be placed in .gitignore to prevent password and username from being put up public on the internet.
notification.py
# ======
# to be placed in a separate, new file called notification.py in same directory as long process.
# mygamilaccount@gmail.com - a gmail account that will be sending the note.
# mygmailpassword - the password to the above account.
# sendtoemail@gmail.com - the gmail account that you'll be notifying.
import smtplib
def email_notification_on_completion():
content = ("Process finished")
mail = smtplib.SMTP('smtp.gmail.com', 587)
mail.ehlo()
mail.starttls()
mail.login('mygmailaccount@gmail.com', 'mygmailpassword')
mail.sendmail('mygmailaccount@gmail.com', 'sendtoemail@gmail.com', content)
mail.close()
print("Notification Sent")
def main():
email_notification_on_completion()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment