Guest User

Untitled

a guest
Aug 25th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import random
  3. import smtplib
  4. from email.mime.text import MIMEText
  5.  
  6. SMTP_SERVER = None # 'smtp.gmail.com'
  7. SMTP_PORT = None # 587
  8. EMAIL_ACCOUNT_USERNAME = None # 'mymemail@example.org'
  9. EMAIL_ACCOUNT_PASSWORD = None # 'mypassword
  10. EMAIL_SUBJECT = None # 'Secret friend'
  11. EMAIL_FROM = None # 'mymemail@example.org'
  12.  
  13. people = [
  14. # ('NOMBRE', 'EMAIL'),
  15. ]
  16.  
  17. amigos = list(people)
  18.  
  19. ok = False
  20. while not ok:
  21. random.shuffle(amigos)
  22. for p, a in zip(people, amigos):
  23. if p == a:
  24. break
  25. else:
  26. ok = True
  27. else:
  28. s = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
  29. s.starttls()
  30. s.login(EMAIL_ACCOUNT_USERNAME, EMAIL_ACCOUNT_PASSWORD)
  31. for p, a in zip(people, amigos):
  32. # print '%s: %s' % (p[0], a[0])
  33. msg = MIMEText('%s --> %s' % (p[0], a[0]))
  34. msg['Subject'] = EMAIL_SUBJECT
  35. msg['From'] = EMAIL_FROM
  36. msg['To'] = p[1]
  37. s.sendmail(EMAIL_FROM, [p[1]], msg.as_string())
  38. s.quit()
Add Comment
Please, Sign In to add comment