functions.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import smtplib
  2. from email.message import EmailMessage
  3. def check_password(password=''):
  4. smb = 'qwertyuiopasdfghjklzxcvbnm'
  5. if len(password) < 6:
  6. return 'Пароль должен быть длиннее 6 символов'
  7. elif False in [True if i.isalpha() and i.lower() in smb or i.isdigit() else False for i in password]:
  8. return 'Пароль может содержать только буквы латинского алфавита и цифры'
  9. elif True not in [True if i.isdigit() else False for i in password]:
  10. return 'Пароль должен содержать буквы разного регистра и цифры'
  11. elif False not in [True if i.islower() and i.isalpha() else False for i in password]:
  12. return 'Пароль должен содержать буквы разного регистра и цифры'
  13. else:
  14. return 'OK'
  15. def mail(msg, to, topic='Подтверждение почты'):
  16. file = open('mail.incepted', 'r', encoding='utf-8').readline().split()
  17. login, password = file[0], file[1]
  18. email_server = "smtp.yandex.ru"
  19. sender = "incepted@yandex.ru"
  20. em = EmailMessage()
  21. em.set_content(msg)
  22. em['To'] = to
  23. em['From'] = sender
  24. em['Subject'] = topic
  25. mailServer = smtplib.SMTP(email_server)
  26. mailServer.set_debuglevel(1)
  27. mailServer.ehlo()
  28. mailServer.starttls()
  29. mailServer.ehlo()
  30. mailServer.login(login, password)
  31. mailServer.ehlo()
  32. mailServer.send_message(em)
  33. mailServer.quit()