Last active
May 29, 2019 00:44
-
-
Save nt92/26f5e4a31f738a89f6304f1f17cf77f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sqlite3 | |
| import smtplib | |
| FROM_ADDRESS = 'nthota.testing@gmail.com' | |
| TO_ADDRESS = 'nthota92@gmail.com' | |
| PASSWORD = 'wouldnt_you_like_to_know' | |
| conn = sqlite3.connect('entries.db') | |
| cursor = conn.cursor() | |
| # fetch random entry object | |
| cursor.execute("SELECT * FROM entries ORDER BY RANDOM() LIMIT 1") | |
| entry_object = cursor.fetchone() | |
| date = entry_object[0] | |
| entry = entry_object[1] | |
| # set up email server | |
| server = smtplib.SMTP(host = 'smtp.gmail.com', port = 587) | |
| server.ehlo() | |
| server.starttls() | |
| server.login(FROM_ADDRESS, PASSWORD) | |
| # create message | |
| message = (date + '\n' + entry).encode('utf-8') | |
| server.sendmail(FROM_ADDRESS, TO_ADDRESS, message) | |
| print(message) | |
| del message | |
| server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment