0

I'm trying to use SMTPLIB in python to send a message, however I get an error message. I'm positive that the e-mail and passwords used are correct. I have tried to send this with and without signing in via web browser. I have allowed less secure sources from the SENDERS email as the following stackoverflow article states : Error sending email: raise SMTPAuthenticationError(code, resp). I have substituted words instead of actual emails and passwords in the below code:

import smtplib

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("senderemail", "senderemailpassword")

msg = "Hello!"
server.sendmail("senderemail", "recieveremail", msg)
server.quit()

Error message:

Traceback (most recent call last):
  File "D:\Hussain\Hussain's computing\Python\emailingtest.py", line 5, in <module>
    server.login("senderemail", "senderpassword")
  File "C:\Users\Hammad\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 730, in login
    raise last_exception
  File "C:\Users\Hammad\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 721, in login
    initial_response_ok=initial_response_ok)
  File "C:\Users\Hammad\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 642, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvT\n5.7.14 ULHSk5VkFjTMqIX_jl5P4GMOarejb0s0WpOqP5RRrWPijD_2GRXQ--JBo5t2r_5pz-ysoY\n5.7.14 Eqv-0GUXB4v321WRxe2uRR1FlFqSTWy-qwXSDmXkkWqwah1akDIy4iw73_mach6-KntI0A\n5.7.14 HLVsfpyrYaTDdeJd54pUPlCEI5W9kZiv48-Ir2-NhbL_rqHrg3OrC-432Uc90Rskt9qNd0\n5.7.14 vAm9r3GQr8jUxrYIgj9YUP0h8xr8HKFFDQSX_RcuTn2lSrXIuy> Please log in via\n5.7.14 your web browser and then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 h7-v6sm8163217wrs.3 - gsmtp')

It would be very helpful if someone could fix my code.

Hussain Hammad
  • 125
  • 2
  • 14

2 Answers2

0

Google blocks by default any attempts of login from script/application which does not use modern security standards. However you can change that settings on: https://www.google.com/settings/security/lesssecureapps.

mcjay
  • 115
  • 1
  • 8
0

As mentioned in this tutorial it may be worth Displaying the unlock captcha.

Keir
  • 752
  • 5
  • 8