Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. # A test to make sure my VPS can do crontab right
  2. # */5 * * * * python /PATH/TO/cron-test.py > /PATH/TO/log 2>&1
  3.  
  4. import smtplib
  5. import datetime
  6.  
  7. now = datetime.datetime.now().strftime('%H:%M:%S')
  8.  
  9. def print_result(string):
  10. print(now)
  11. print(string)
  12. print()
  13.  
  14. gmail_user = '' # Gmail address
  15. gmail_password = '' # Gmail password
  16.  
  17. sent_from = gmail_user
  18. to = '' # Destination address
  19. subject = 'crontab test'
  20. body = 'automated email for ' + now
  21.  
  22. email_text = '''\
  23. From: %s
  24. To: %s
  25. Subject: %s
  26.  
  27. %s
  28. ''' % (sent_from, to, subject, body)
  29. try:
  30. server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
  31. server.ehlo()
  32. server.login(gmail_user, gmail_password)
  33. server.sendmail(sent_from, to, email_test)
  34. server.close()
  35. print_result('email sent')
  36. except Exception as err:
  37. print_result(err)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement