Skip to content

Instantly share code, notes, and snippets.

@nt92
Last active May 29, 2019 00:44
Show Gist options
  • Select an option

  • Save nt92/26f5e4a31f738a89f6304f1f17cf77f3 to your computer and use it in GitHub Desktop.

Select an option

Save nt92/26f5e4a31f738a89f6304f1f17cf77f3 to your computer and use it in GitHub Desktop.
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