Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import random
- import smtplib
- from email.mime.text import MIMEText
- SMTP_SERVER = None # 'smtp.gmail.com'
- SMTP_PORT = None # 587
- EMAIL_ACCOUNT_USERNAME = None # 'mymemail@example.org'
- EMAIL_ACCOUNT_PASSWORD = None # 'mypassword
- EMAIL_SUBJECT = None # 'Secret friend'
- EMAIL_FROM = None # 'mymemail@example.org'
- people = [
- # ('NOMBRE', 'EMAIL'),
- ]
- amigos = list(people)
- ok = False
- while not ok:
- random.shuffle(amigos)
- for p, a in zip(people, amigos):
- if p == a:
- break
- else:
- ok = True
- else:
- s = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
- s.starttls()
- s.login(EMAIL_ACCOUNT_USERNAME, EMAIL_ACCOUNT_PASSWORD)
- for p, a in zip(people, amigos):
- # print '%s: %s' % (p[0], a[0])
- msg = MIMEText('%s --> %s' % (p[0], a[0]))
- msg['Subject'] = EMAIL_SUBJECT
- msg['From'] = EMAIL_FROM
- msg['To'] = p[1]
- s.sendmail(EMAIL_FROM, [p[1]], msg.as_string())
- s.quit()
Add Comment
Please, Sign In to add comment