'smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server. Python

  1. I am attempting to run a python script to automate sending emails but I keep running into this error.

Any suggestions on how to fix this?

 import smtplib
 from email import message


 from_addr = '[email protected]'
 to_addr = '[email protected]'
 subject = 'Test Email'
 body = 'Test'
 msg = message.Message()
 msg.add_header('from', from_addr)
 msg.add_header('to', to_addr)
 msg.add_header('subject', subject)
 msg.set_payload(body)
 server = smtplib.SMTP('smtp.gmail.com', 587)
 server.login(from_addr, 'password')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program `Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\smtplib.py", line 716, in login`
    raise SMTPNotSupportedError(

smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.



Solution 1:[1]

I'm not shure, but for gmail you need https://myaccount.google.com/lesssecureapps Allow less secure apps: ON setting.

Or you need Google APIs for authentication: https://developers.google.com/gmail/api/quickstart/python

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Radek Rojík