Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A test to make sure my VPS can do crontab right
- # */5 * * * * python /PATH/TO/cron-test.py > /PATH/TO/log 2>&1
- import smtplib
- import datetime
- now = datetime.datetime.now().strftime('%H:%M:%S')
- def print_result(string):
- print(now)
- print(string)
- print()
- gmail_user = '' # Gmail address
- gmail_password = '' # Gmail password
- sent_from = gmail_user
- to = '' # Destination address
- subject = 'crontab test'
- body = 'automated email for ' + now
- email_text = '''\
- From: %s
- To: %s
- Subject: %s
- %s
- ''' % (sent_from, to, subject, body)
- try:
- server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
- server.ehlo()
- server.login(gmail_user, gmail_password)
- server.sendmail(sent_from, to, email_test)
- server.close()
- print_result('email sent')
- except Exception as err:
- print_result(err)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement