sending email from python 3.4 script, WITHOUT enabling 'less secure apps' in gmail
Question: i would like to send mail using a python 3.4 script, from my gmail address. i
use the following code:

    
    
    import smtplib  
    
    def sendmail():  
        sender='myemail@gmail.com'  
        receiver=['someone@gmail.com']  
        message='text here'  
        try:  
            session=smtplib.SMTP('smtp.gmail.com',587)  
            session.ehlo()  
            session.starttls()  
            session.ehlo()  
            session.login(sender,'mypassword')  
            session.sendmail(sender,receiver,message)  
            session.quit()  
        except smtplib.SMTPException:  
            print('Error, can not send mail!')
    

if i 'allow less secure apps' in my gmail account, the script works fine.
however, if i disable 'less secure apps', it doesn't works (i get a warning
email from google, with 'sign-in attempt blocked') . i would like to modify my
code, to be able to send mail without enabling this thing.

i have read all the questions and answers regarding similar problems, but did
not find any useful answers or methods. someone has any solution for this?


Answer: From ["Allowing less secure apps to access your account" support
page](https://support.google.com/accounts/answer/6010255)

> Google may block sign in attempts from some apps or devices that do not use
> modern security standards.

A login/password is not a modern mechanism to authenticate. You should
implement [SASL XOAuth2](https://developers.google.com/gmail/oauth_overview).

