Skip to content

Instantly share code, notes, and snippets.

@montarion
Created November 9, 2016 21:28
Show Gist options
  • Save montarion/14da35f6ee29e2de85c4dd36d1b24485 to your computer and use it in GitHub Desktop.
Save montarion/14da35f6ee29e2de85c4dd36d1b24485 to your computer and use it in GitHub Desktop.
alle code om email te lezen van de ontvanger en te verzenden van uit de server
def email(email):
import getpass, poplib
#server credentials
Mailbox = poplib.POP3_SSL('pop.googlemail.com', '995')
Mailbox.user('[email protected]')
Mailbox.pass_('Hondenbijeenkomst')
numMessages = len(Mailbox.list()[1])
mailbestand = open('lastemail.txt', 'w')
for i in range(numMessages):
for msg in Mailbox.retr(i+1)[1]:
#print(msg)
mailbestand.write(str(msg))
Mailbox.quit()
mailbestand = open('lastemail.txt', 'r')
auth = mailbestand.read()
if auth == '':
print('failure')
final = False
else:
print('pass')
final = True
mailbestand.close()
if final == True:
return True
if email(email) == True:
from random import choice
from string import ascii_letters
def twofactorauthentication():
rndmlettercode = ''.join(choice(ascii_letters)for x in range(9))
infile = open('bestand', 'w')
infile.write(rndmlettercode)
infile.close()
file = open('bestand', 'r')
file = file.read()
outfile = open('bestanduit', 'w')
deletword = '='
for line in file:
for word in deletword:
line = line.replace(word, '')
outfile.write(line)
outfile.close()
outfile = open('bestanduit', 'r')
outfile = outfile.read()
#
print(outfile)
emailto = input('Geef u email op: ')
while emailto == '':
emailto = input('Geef u email op: ')
else:
print('Er wordt een email gestuurd naar '+ emailto +', check u spam en normale inbox.')
import smtplib
fromaddress = 'specselect@gmailcom'
toaddress = emailto
message = '\r\n'.join(['from: [email protected]',
'to: '+emailto,
'subject: Authenticatiecode',
'',
'Uw authenticatiecode is: '+outfile])
gebruikersnaam = '[email protected]'
wachtwoord = 'Hondenbijeenkomst'
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(gebruikersnaam,wachtwoord)
server.sendmail(fromaddress,toaddress,message)
server.quit()
authfile = input('Geef u authenticatiecode op, u heeft 4 kansen: ')
counter = 0
while True:
if authfile == outfile:
print('Authenticatiecode correct, fijne dag verder! ')
break
else:
counter += 1
print('Authenticatiecode incorrect, probeer het nogmaals')
authfile = input('Geef u authenticatiecode op: ')
if counter == 3 and authfile != outfile:
print('U heeft te vaak de verkeerde authenticatiecode opgegeven, probeer het nog eens over 10 minuten. ')
break
twofactorauthentication()
else:
print("") #hier t nummer van een van ons neerzetten?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment