Wouldn’t it be great to get an email once a script has finished letting you know if it worked or failed? Well it’s actually really easy to pull off. Here’s how I did it:
Note for this example you would replace ‘smtp.example.com’ with your email host.
def SendEmail(sender, receivers, message): import sys, smtplib try: smtpObj = smtplib.SMTP('smtp.example.com') smtpObj.sendmail(sender, receivers, message) print 'email sent' except: print 'error sending' sys.exit
message = "my output message" + output #for example. use whatever you want here to convey the info you need receivers = "email@example.com" sender = "firstname.lastname@example.org" SendEmail(sender, receivers, message)