This question has already been answered:

Hi there is such a python script

import smtplib from email.mime.text import MIMEText from email.header import Header # Настройки mail_sender = 'mail@gmail.com' mail_receiver = 'mail@gmail.com' username = 'mail@gmail.com' password = '123fuckypu' server = smtplib.SMTP('smtp.gmail.com:587') # Формируем тело письма subject = u'Тестовый email от ' body = u'Отправка письма на Питтоне ' msg = MIMEText(body, 'plain', 'utf-8') msg['Subject'] = Header(subject, 'utf-8') # Отпавляем письмо server.starttls() server.ehlo() server.login(username, password) server.sendmail(mail_sender, mail_receiver, msg.as_string()) server.quit() 

works for all other mail (mail.ru, yandex, ru, etc.), gmail gives an error (although gmail has configured authentication of secure applications):

 Traceback (most recent call last): File "C:\Users\f0st\Desktop\post.py", line 21, in <module> server.login(username, password) File "C:\Program Files\Python36\lib\smtplib.py", line 729, in login raise last_exception File "C:\Program Files\Python36\lib\smtplib.py", line 720, in login initial_response_ok=initial_response_ok) File "C:\Program Files\Python36\lib\smtplib.py", line 641, in auth raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvx\n5.7.14 gfl4heOeAD4f_iQHRXx-gPwNRGalRzc6UXknyTR4xAiAWK5KENf-Q0gfE5811Z-SqRn7Rq\n5.7.14 cukkiOrcc4Twik4nRwhlY5Gsh23mwu32lwuotv-WQAbGMDBlXIN7lIlf03wAwD4wQPyXNM\n5.7.14 A3XnnjwqoBLpd7LA8kjQHm3widA29l-S5QTm9MT4pvhJ-vkB9T7U7vhMF_oWYuJgKSW_fP\n5.7.14 87fJSF-abKA-ow3gruty4wTyATCdE> 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 u30sm8540501wru.88 - gsmtp') 

Reported as a duplicate by jfs python Apr 22 '18 at 12:20 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • They also wrote to you: Please log in via your web browser and \ n5.7.14 then try again. - KAGG Design
  • Yes, I saw, but the problem is that I am authorized! - Sciner
  • the code can already work as it is, although a better documented interface can be used and sent by host, port separately¶ As @KAGGDesign has already said, the error message asks you to manually log into your account through the browser and try again after that. - jfs

1 answer 1

I implemented the dispatch as follows:

 content = 'Это внутренности письма' mail = smtplib.SMTP('smtp.gmail.com', 587) mail.ehlo() mail.starttls() mail.login('komp.lord@gmail.com','########не скажу') mail.sendmail('komp.lord@gmail.com', 'komp.lord@gmail.com', content)