I am aware of the following up front:
- Google requires the less secure apps setting
- 2.7 is not the most efficient version to do this in Python
- UTF-8 is unnecessary with this character list, but I have plans to expand so I have that in place for a new phase
I'm not interested in learning 3.X Python right now plus this is for a spy game so date sensitivity was important. With that out of the way, the issue is a PythonAnywhere issue. The following code is the culprit:
# -*- coding: utf-8 -*-
# Base character list
cipher = [" ","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9",".",",","!","?","@","(",")","[","]","$","%","-","+","=","#","*","&","~","/","_","'",'"'];
# Random number generator to initiate blind encryption
from random import randint
lock = randint(1,len(cipher)) #Inclusive
# Defined variables, lists, etc as needed
retain = []
n = len(cipher)
#key = n - lock
exhibit = []
secret = ''
unlock = raw_input('Enter your key (For decryption only): ') # Flag for decryption
conceal = raw_input('Enter your message now: ') # Original message from user
# Loop to find data
for i in range(len(conceal)):
# Returns index (in cipher) of each character from input
retain.append(cipher.index(conceal[i]))
# Determine if we need to Encrypt or Decrypt
if unlock == '':
# Enforce key is only used for decryption
key = n - lock
# Offsets index above of each character from input by lock
# The mod allows lock to wrap around to index 0 and keep going
exhibit.append(cipher.index(conceal[i]) + lock % n)
# And print string without quotes and commas
j = (exhibit[i] % n)
secret += ''.join(cipher[j])
else:
# Enforce key is taken from user
key = int(unlock)
exhibit.append(cipher.index(conceal[i]) + key % n)
# And print string without quotes and commas
j = (exhibit[i] % n)
secret += ''.join(cipher[j])
if key == n - lock:
# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
fromaddr = 'XXX@gmail.com' # Standard Sending Address
username = 'XXX@gmail.com'
toaddr = raw_input('Enter your drop address now: ') # Recipient Email Address
password = '*******'
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = 'Message from Agent %s' % key
body = secret + '\n' + '\n' + 'This message has been delivered through the Dead Drop Service. You may also use this service to decrypt your message. Please visit lalala to began the decryption process.'
msg.attach(MIMEText(body, 'plain'))
# Send the message via our own SMTP server, with normal headers, subject, and body.
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(username, password)
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
else:
# Prints indices
#print(retain)
#print(lock)
#print(key)
#print(exhibit)#.encode)
print(secret)#.encode)
This wonderful bit of coding gives me the following error:
Traceback (most recent call last): File "DeadDropEng.py", line 68, in <module> server.login(username, password) File "/usr/lib/python2.7/smtplib.py", line 622, in login raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (534, '5.7.14 https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbtuH\n5.7.14 VKsANiVYRXimrcvXWOIZAF3sShMn0NNVlRkje9m9Prk2YdAhrLEq_6hfAv2dM-G9b5MZNr\n5.7.14 MOtoKuL9I8f1fXp7AUBT3THasSG_p6q0pYHQxJOL45anuHlHvtxH2P3YWKoVv_TsgN3pw5\n5.7.14 nR7zZu3zaLCHVdxfO0J_zB37eiAbXKznsJI9BzW5iKt-5SyH-XS04UzO3bP_Hk79XEnOQR\n5.7.14 7ELs3LA2Kb6HIA-at0tLB0mz6iks Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 b201sm7661962qhb.48 - gsmtp')
BUT if I run this same code on my desktop, it works perfectly. Sends the email without any issues or errors. Any clues?
Thanks in advance.