Though I'm not familiar scheduling Models with task scheduler, for python scripts, I use sendmail for that.
In my script, I have a Mailer() function
import smtplib
from email.mime.text import MIMEText
msgtext = 'default text for message'
subtext = 'default text for subject'
def Mailer():
############################################
##Variables to set for notification emails##
############################################
server = smtplib.SMTP(MSERV)
TO = [MTO] # set to email you want results sent to
FROM = MFROM # set to email you want results sent FROM
msg = MIMEText( msgtext )
msg['Subject'] = subtext
msg['From'] = FROM
msg['To'] = ','.join(TO)
server.sendmail(FROM, TO, msg.as_string())
server.quit()
If there are any errors, the except: block modifies the msgtext and subtext to include error message stuff:
msgtext = '--ERROR----------ERROR----------ERROR----------ERROR--\nPYTHON ERRORS:\nTraceback Info:\n' + tbinfo + '\nError Info:\n' + str(sys.exc_type) + ': ' + str(sys.exc_value) + '\n'
subtext = 'Program Failed.'
Then, in my finally: block, I run
Mailer()
This way, I always get an email with default message UNLESS there was an error, then I get the error as well.
R_