'Google smpt connection failed [duplicate]

I tried connecting and sending mail using google server on my vscode powershell and windows cmd but both are returning different errors

On Vscode Powershell it shows : line 359, in send raise SMTPServerDisconnected('please run connect() first')

while on windows cmd it shows: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials j8-20020a05600c404800b0038cc9c7670bsm11241442wmm.3 - gsmtp')

this is my configuration

set MAIL_PORT=587
set MAIL_USE_TLS=1
set MAIL_USERNAME=<my-gmail-username>
set MAIL_PASSWORD=<my-gmail-password>

this is the app sender

>>> from app import mail
>>> msg = Message('test subject', sender=app.config['ADMINS'][0],
... recipients=['[email protected]'])
>>> msg.body = 'text body'
>>> msg.html = '<h1>HTML body</h1>'
>>> mail.send(msg)

I also tried disenabling less small secure app and also using an app password secure but still it didnt work



Solution 1:[1]

The login information may be invalid or Gmail blocked your account for logging in from an unidentified device. You can try it after disable less secure option from Gmail by https://myaccount.google.com/u/0/lesssecureapps

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ashbringer