Я не могу заставить эту программу войти в систему и отправить письмо - PullRequest
0 голосов
/ 24 октября 2019

Я не могу получить электронное письмо для отправки. Когда я ввожу свои данные для входа в систему, он говорит, что что-то пошло не так ..

Мне просто нужно сделать запрос на вход в систему и отправить электронное письмо программой.

Я включил менее безопасные приложения вGMail. Я сделал это после того, как Google заблокировал приложение от доступа, поэтому я не знаю, что я сделал не так. Это может быть сам мой код. Я довольно новичок в этом.

import random
fb = ("Facebook")
fb2 = ("facebook")
facebook = ("Follow us on Facebook at @TheNeatShop")
randname = (" is a cool name.", " is an interesting name.", " is a memorable name.")
name = input("What is your first name?")
print("Hello " + str(name) + ",")
print (name + random.choice(randname))
age = int(input("What is your age?"))
if (age >= 18):
    print("Since you are " + str(age) + " years old you will be directed to suitable content for adult consumers.")
elif (age > 13 and age < 18):
    print("Since you are " + str(age) + " years old, you will be shown products recommended for teenagers that are minors.")
elif (age > 1 and age < 13):
    print("We do not have any products for any age group below teenagers. Please do not access the internet without an adults permission and supervision.")
social = input("Please input one of the social platforms you use:")
if (social == fb or social == fb2):
    print(facebook)
else:
    print("We do not have an account for the platform you listed.")
interest = int(input("Enter your interest level with our brand from 1 to 10 with 1 being none to 10 being a lot of interest:"))
if (interest <= 5 and interest >= 1):
    print("Please contact us at neatshopsupport@ns.com with feedback about how we can do better.")
elif (interest > 5 and interest < 8):
    print("Thank you for your rating and we will take note of your mid range rating for improvement.")
elif (interest > 10 or interest < 1):
    print("Please use a number that is 1 through 10.")
else:
    print("We value your high rating as it shows we are making good progress.")
extra = input("Do you have any extra info we should know about you as a customer?")
print("Thank you for your time.")

guser = input("Enter your Gmail user:")
gpass = input("Enter your Gmail password:")

import smtplib


gmail_user = (guser)
gmail_password = (gpass)


sent_from = gmail_user
to = ['hajaren1466@gmail.com']
subject = ('Survey from customer')
body = (str(name) + " " + str(age) + " " + str(social) + " " + str(interest) + " " + str(extra))
email_text = (str(name) + " " + str(age) + " " + str(social) + " " + str(interest) + " " + str(extra))

try:
     server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
     server_ssl.ehlo()
     server_ssl.login(gmail_user, gmail_password)
     server_ssl.sendmail(sent_from, to, email_text)
     server_ssl.close()

     print ('Email sent!')
except:
    print ('Something went wrong...')

Я ожидал, что письмо будет отправлено и логин будет успешным. Моя программа не может войти или что-то не получилось в долгосрочной перспективе, из-за чего она не работает.

...