Python Forum

Full Version: Sending E-mails
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I am trying to just learn how to send e-mails with python. I have found some code online and I am trying to use it but an error keeps appearing. This is the code I am trying to use.
import smtplib

server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.login("my_email", "my_password")
server.sendmail(
  "from_email", 
  "to_email", 
  "Test Message")
server.quit()
When I do this, this is what happens:
Output:
Traceback (most recent call last): File "C:\Users\keega\OneDrive\Documents\Python\Email Sender.py", line 4, in <module> server.login("k*************[email protected]", "K*****123") File "C:\Users\keega\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 730, in login raise last_exception File "C:\Users\keega\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 721, in login initial_response_ok=initial_response_ok) File "C:\Users\keega\AppData\Local\Programs\Python\Python36-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=AKgnsbua\n5.7.14 BWQcAmZiJozJSC9UqHf-MDmwIwlPfsh2QD_0n8TN8Lwr1Jx6EXt33UVEyOBgAXJHTNvnXX\n5.7.14 Y3yIr1HUR877awIHRkPYpljnbMIt6UpOK66N7MISLFL_qG-BHQNqFXGMcT23yQbMVDiugI\n5.7.14 yeBgR7_P84SEH-8MFZjQ38inz0tIJP8S1dB7yr2_4K6n-ONQdtxEGYV71D_FEyRzCzfNyL\n5.7.14 5l6psrK-kOCcl03uzz5HlxUWnjo80nJA_VXUCaCiBsuJLuRBjp> 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 c68-v6sm18546669pfj.51 - gsmtp')
Does anyone know what is wrong and how to fix it?
Thanks :)
This error is probably caused because Google blocks sign-in attempts from lesser secured apps. If you login to your gmail account you probably received also an email regarding a lesser secured app trying to sign in to your account?

If you want to turn off this safety feature you can do that here: https://www.google.com/settings/security/lesssecureapps
Here's a troubleshooting guide that should work.

Most likely problem is of "Allowing less secure apps" Go to THIS link and allow less secure apps to login into the account.
Hello Again,
Thank you it has worked. I already did this, but for some reason it didn't work but I did it again and now works fine.
Thank You Both