Advertisement
Guest User

Untitled

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