Skip to content

Instantly share code, notes, and snippets.

@seffignoz
Last active March 22, 2016 16:56
Show Gist options
  • Save seffignoz/f6b55b4fbe5dd7520e37 to your computer and use it in GitHub Desktop.
Save seffignoz/f6b55b4fbe5dd7520e37 to your computer and use it in GitHub Desktop.
#!/bin/env python
# -*- coding: UTF-8 -*-
#
# (c) Roberto Gambuzzi
# Created: 14/02/2011 15.41.12
# Modified: 04/03/2011 20.25.50
#
# v 0.0.1.0
#
# file: mailmetheerror.py
# auth: Roberto Gambuzzi <gambuzzi@gmail.com>
# desc:
#
# $Id: mailmetheerror.py 04/03/2011 20.25.50 roberto $
# --------------
import sys
import traceback
FROM = 'test@test.com'
TO = 'test@gmail.com'
SMTP = 'smtp.tin.com'
def mail(sb, text):
try:
import smtplib
from email.MIMEText import MIMEText
msg = MIMEText(text)
msg['From'] = FROM
msg['To'] = TO
msg['Subject'] = 'Error from '+sb
s = smtplib.SMTP()
s.connect(SMTP)
s.sendmail(FROM,TO, msg.as_string())
s.close()
except:
pass
def install_excepthook():
def my_excepthook(exctype, value, tb):
text = ''.join(traceback.format_exception(exctype, value, tb))
mail(str(sys.argv[0]), text)
print text
sys.excepthook = my_excepthook
install_excepthook()
if __name__=="__main__":
mail(__file__,'Prova')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment