I used this script to sending status report to my team lead. It will read the status from the file Readme.md. Here i already wrote my status. if this script execute on target_time or greater than it will execute the mailer function otherwise ask for confirmation
# importing messagebox for confirmation diaglog box
import tkMessageBox
import smtplib
from time import gmtime, strftime
def mail_send():
target_time = 02
# By using strftime we only current time in hours, it returns string like
# "12"
current_Time = strftime("%H")
print current_Time
# convert str to number
cTime = int(current_Time)
def sub_mailer():
print "Mailer loading ...."
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login('[email protected]', 'anypass')
f = open('Readme.md', 'r')
filedata = f.read()
subject = "Today Update"
msg = 'Subject:{}\n\n{}'.format(subject, filedata)
s.sendmail('[email protected]', '[email protected]',
msg)
s.quit()
f.close()
# get time using time module
if target_time <= cTime:
sub_mailer()
else:
status = tkMessageBox.askquestion(
"Shift hours is not completed. Shall i send a mail", icon="warning")
if status == "yes":
sub_mailer()
else:
print "Mail sending process was canceled by user"