· 8 years ago · Feb 06, 2018, 09:34 PM
1 import smtplib
2import imaplib
3import sched, time
4from email.mime.multipart import MIMEMultipart
5from email.mime.text import MIMEText
6import json
7from pymongo import MongoClient
8
9qa = {}
10client = MongoClient()
11db = client.questions
12collection = db.qcollection
13
14def input_questions():
15maxlength = 0
16i = 0
17
18while True:
19try:
20maxlength = int(input("How many questions do you want to ask? "))
21except ValueError:
22print ("You must type a number.")
23else:
24break
25
26for i in range(maxlength):
27q = input("Enter a question: ")
28a = input("Enter the expected answer: ")
29qa[q] = a
30print ('Question: ' + q + ' ' + 'Answer: ' + a)
31
32def email_questions():
33print ("Thank you. You will receive the response shortyly.")
34server = smtplib.SMTP('smtp.gmail.com', 587)
35server.ehlo()
36server.starttls()
37server. ehlo()
38server.login("j@gmail.com", "")
39fromaddr = "@gmail.com"
40toaddr = "j@gmail.com"
41msg = MIMEMultipart()
42msg['Fromaddr'] = fromaddr
43msg['Toaddr'] = toaddr
44msg['Subject'] = "Questions"
45body = "Answer these questions"
46message = [body] + qa
47formatted_message = '\n'.join(message)
48msg.attach(MIMEText(formatted_message, 'plain'))
49text = msg.as_string()
50server.sendmail(fromaddr, toaddr, text)