Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- import random
- # Define mailing targets names and their corresponding email addresses.
- mailingAccountList = [{"Andrew" :"ceciltitanwave@gmail.com"},
- {"Maddie" :"mwooden1@binghamton.edu"},
- {"Tyler" :"tmille20@binghamton.edu"},
- {"Alex" :"aebange@gmail.com"},
- {"Nick" :"nick.miller.2000.nm@gmail.com"},
- {"Gillian":"gilliankhulbert@gmail.com"},
- {"James" :"jamesdfarrow14@gmail.com"},
- {"Clare" :"clare_osborn9@aol.com"}]
- mailingAccountsDict = {"Andrew": "ceciltitanwave@gmail.com",
- "Maddie" : "mwooden1@binghamton.edu",
- "Tyler" : "tmille20@binghamton.edu",
- "Alex" : "aebange@gmail.com",
- "Nick" : "nick.miller.2000.nm@gmail.com",
- "Gillian": "gilliankhulbert@gmail.com",
- "James" : "jamesdfarrow14@gmail.com",
- "Clare" : "clare_osborn9@aol.com"}
- # Define sender's account information
- userName = "GugsXMas2018@gmail.com"
- userPass = "Gugs2018"
- # Define the location and port of the desired SMTP server
- mail = smtplib.SMTP("smtp.gmail.com", 587)
- def randomNumbers():
- numbers_list = [i for i in range(len(mailingAccountList))]
- return numbers_list
- # Assign targets to participants
- def santasList(x):
- # Instantiate lists and variables
- givers_list = x
- receivers_list = x
- pairs_list = []
- naughty_list = []
- i = 0
- z = True
- remaining_names_list = []
- # Create a localized list of all the names
- for item in mailingAccountList:
- remaining_names_list.append(list(item)[0])
- mailing_accounts_length = len(mailingAccountList)+1
- # Create two localized lists of numbers to be randomized with corresponding list items
- while z == True:
- for item in tuple(x):
- # Define a santa
- santa = item
- # Define a child
- child = random.choice(receivers_list)
- # Check to make sure the child isn't the same as the santa
- if santa == child:
- child2 = random.choice(receivers_list)
- # The RNG is being a bitch and your child is the same as the santa
- if santa == child:
- # The random number generator is being a REALLY BIG fucking bitch and we need to rerun the ENTIRE for loop
- break
- else:
- # Return to standard operation
- break
- else:
- # The child is now going to get a gift, remove them from the list
- receivers_list.remove(child)
- # Add the pair to the list of pairs
- pairs_list.append({santa : child})
- # Check to see if there's anyone still unaccounted for
- if len(receivers_list) == 0:
- # Everyone has been assigned, time to move on
- z = False
- else:
- # There is still work to be done, continue
- pass
- # We now have our pairs list, time to change numbers to names
- for item in pairs_list:
- # Retrieve the value from the current key
- current_number = list(item.values())[0]
- # Replace the key values with names
- naughty_list.append({remaining_names_list[i]: remaining_names_list[current_number]})
- i+=1
- # Return the naughty list so we can mail it
- return naughty_list
- # Launch the reindeer to deliver the naughty list to the secret Santa's inboxes
- def launchReindeer(naughtyList):
- # Parse through the items in our "naughty list"
- for item in naughtyList:
- # Separate the keys and their corresponding values
- key = (list(item)[0])
- # Take the key and find it's corresponding email
- email_target = mailingAccountsDict[key]
- subject = "GUG XMAS SECRET SANTA TARGET 12/29/18"
- value = (""""
- To: %s <%s>
- From: GUGBLASTER9000 2.15
- Greetings fellow gug,
- In anticipation of our upcoming Christmas party, December 29th - we are sending out a 'Secret Santa' list. You are receiving this email because you did not opt out of the Secret Santa activities.
- If you would like to opt out, tell Rudy IMMEDIATELY. At the bottom of this email, you should see a name - if you don't, Alex is currently at his computer swearing profusely.
- The name at the bottom represents the person you should be buying a secret gift for.
- The spending limit is currently set at $20.00, if you go significantly below the limit you will look like Cam, and if you go over the limit you will look like a COMPLETE FOOL.
- Remember to get something soon as the date is only 18 days away (from the date this was sent).
- THE PERSON YOU WILL GIVE A GIFT TO IS: %s.""" % (key,email_target,item[key]))
- msg = 'Subject: {}\n\n{}'.format(subject, value)
- # Dispatch the reindeer
- mail.sendmail(userName,email_target,msg)
- print("Sent target to %s at %s." % (key, email_target))
- # Generate a dictionary of randomly generated paired numbers
- numbersList = randomNumbers()
- # Generate a dictionary containing randomly paired names
- naughtyList = santasList(numbersList)
- # Identify ourselves to the SMTP server
- mail.ehlo()
- # Enable transport layer security (TLS) encryption
- mail.starttls()
- # Login to our email account
- mail.login(userName,userPass)
- # Dispatch the reindeer to send our message
- launchReindeer(naughtyList)
- # Close the stables and pack up shop
- mail.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement