kootenpv / yagmail

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

authentication problem with Notebooks Azure (Microsoft) and Google Colab #162

Open grodnera opened 4 years ago

grodnera commented 4 years ago

yagmail works great on desktop whether I am on Windows or Lubuntu. However, when I use the same code on Azure Notebooks (Microsoft) or Colab Research (Google) I have the following authentication message.

Note1: I use modules -urllib- and -requests- for webscrapping and that part works without a problem. For example, the code has no problem filling out Google Form to collect data. Note2: Gmail is enabled to work with less secure apps and the particular account works flawlessly with yagmail around the clock, just on desktop Lubuntu.

Any comments much appreciated.

====================== OUTPUT BELOW ===============

SMTPAuthenticationError Traceback (most recent call last)

in () 108 yag.send(to="youremail@gmail.com", 109 subject=emailsubject, --> 110 contents=[page] 111 ) 112 5 frames /usr/local/lib/python3.6/dist-packages/yagmail/sender.py in send(self, to, subject, contents, attachments, cc, bcc, preview_only, headers, newline_to_break) 145 ): 146 """ Use this to send an email with gmail""" --> 147 self.login() 148 recipients, msg_string = self.prepare_send( 149 to, subject, contents, attachments, cc, bcc, headers, newline_to_break /usr/local/lib/python3.6/dist-packages/yagmail/sender.py in login(self) 244 self._login_oauth2(self.credentials) 245 else: --> 246 self._login(self.credentials) 247 248 /usr/local/lib/python3.6/dist-packages/yagmail/sender.py in _login(self, password) 202 if not self.smtp_skip_login: 203 password = self.handle_password(self.user, password) --> 204 self.smtp.login(self.user, password) 205 self.log.info("Connected to SMTP @ %s:%s as %s", self.host, self.port, self.user) 206 /usr/lib/python3.6/smtplib.py in login(self, user, password, initial_response_ok) 728 729 # We could not login successfully. Return result of last attempt. --> 730 raise last_exception 731 732 def starttls(self, keyfile=None, certfile=None, context=None): /usr/lib/python3.6/smtplib.py in login(self, user, password, initial_response_ok) 719 (code, resp) = self.auth( 720 authmethod, getattr(self, method_name), --> 721 initial_response_ok=initial_response_ok) 722 # 235 == 'Authentication successful' 723 # 503 == 'Error: already authenticated' /usr/lib/python3.6/smtplib.py in auth(self, mechanism, authobject, initial_response_ok) 640 if code in (235, 503): 641 return (code, resp) --> 642 raise SMTPAuthenticationError(code, resp) 643 644 def auth_cram_md5(self, challenge=None): SMTPAuthenticationError: (534, b'5.7.14 \n5.7.14 Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 b189sm5860036vkg.24 - gsmtp')