Guest User

Untitled

a guest
Jan 27th, 2019
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. import smtplib
  2. from email.message import EmailMessage
  3. from getpass import getpass
  4.  
  5. name = str(input("Name: "))
  6. email = str(input("Email: "))
  7. password = str(getpass("Password: "))
  8. recipient = str(input("Recipient's email: "))
  9.  
  10. while True:
  11. try:
  12. productsnm = int(input(f"Hi, {name}!nHow many products do you want to add to the shopping list? " ))
  13. except ValueError:
  14. print ("Please input a number.")
  15. else:
  16. break
  17.  
  18. products = []
  19. quantities = []
  20.  
  21. for x in range(int(productsnm)):
  22.  
  23. product = str(input('Input the product name: '))
  24.  
  25. while True:
  26. try:
  27. quantity = int(input('Input the product quantity: '))
  28. except ValueError:
  29. print ("Please input a number.")
  30. else:
  31. break
  32.  
  33. products.append(product)
  34. quantities.append(quantity)
  35.  
  36. print ("These products have been added to the shopping list:")
  37.  
  38. for x, y in zip (products, quantities):
  39. print (f'{x} x {y}')
  40.  
  41. gmail_user = email
  42. gmail_password = password
  43.  
  44. msg = EmailMessage()
  45. msg['Subject'] = "Shopping List"
  46. msg['From'] = gmail_user
  47. msg['To'] = [recipient]
  48. message = ""
  49. for i in range(max(len(products), len(quantities))):
  50. message = message + str(products[i]) + " x " + str(quantities[i]) + "n"
  51. msg.set_content(message)
  52.  
  53. try:
  54. s = smtplib.SMTP_SSL('smtp.gmail.com', 465)
  55. s.ehlo()
  56. s.login(gmail_user, gmail_password)
  57. s.send_message(msg)
  58. s.quit()
  59.  
  60. print ('nThe email has been sent.')
  61.  
  62. except:
  63. print ('An error occurred.')
  64.  
  65. print ("nHave a nice day!")
  66.  
  67. exit()
Add Comment
Please, Sign In to add comment