kootenpv / yagmail

Send email in Python conveniently for gmail using yagmail
MIT License
2.66k stars 265 forks source link

How to send an email using OAuth 2.0 automatically without any input #230

Closed Mubashir78 closed 2 years ago

Mubashir78 commented 2 years ago

I am trying to send a recovery-code email to the user's email address when he forgets his Master Password. I want to get off from the "less secure apps" option and use the OAuth option, but upon implementing it (along with the credentials.json file), it asks in the terminal to put the email address of the sender and the verification code. I just want to have it sent automatically to the user's email address from the email address that I've personally created separately for the program/script. How can I do it?

yliapis commented 2 years ago

+1 On this issue, I am also trying to programmatically send emails without user input.

Not sure if I should open a separate issue for this, but I am getting an error with a missing refresh token, not sure how to generate one of these from the google console:

    self.login()
  File "/Users/yliapis/anaconda3/lib/python3.9/site-packages/yagmail/sender.py", line 208, in login
    self._login_oauth2(self.credentials)
  File "/Users/yliapis/anaconda3/lib/python3.9/site-packages/yagmail/sender.py", line 248, in _login_oauth2
    auth_string = self.get_oauth_string(self.user, oauth2_info)
  File "/Users/yliapis/anaconda3/lib/python3.9/site-packages/yagmail/sender.py", line 238, in get_oauth_string
    return get_oauth_string(user, oauth2_info)
  File "/Users/yliapis/anaconda3/lib/python3.9/site-packages/yagmail/oauth2.py", line 96, in get_oauth_string
    access_token, expires_in = refresh_authorization(**oauth2_info)
TypeError: refresh_authorization() missing 1 required positional argument: 'google_refresh_token'

My use case is to simply have automated emails sent every month from a chron triggered script.

dataslug1 commented 2 years ago

I would also like the same please = I had a simple script set up that would login with username and password, but now Gmail does not allow less secure apps so this has stopped working.

kootenpv commented 2 years ago

Go for an application specific password, that works well for me

dataslug1 commented 2 years ago

Indeed that works for me, thank you!