Home >Backend Development >Python Tutorial >Why Does My Python Gmail Email Script Show 'SMTP AUTH Extension Not Supported,' and How Can I Fix It?
Sending Emails with Gmail Using Python: Troubleshooting "SMTP AUTH Extension Not Supported" Error
When attempting to send emails via Gmail using Python, you may encounter the following error:
SMTPException: SMTP AUTH extension not supported by server.
To resolve this issue, we need to use the SMTP_SSL class and establish a secure connection instead of the default SMTP. Follow these steps:
Create an SMTP_SSL object (Port 465):
server_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465)
Login using your Gmail credentials:
server_ssl.login(user, pwd)
Send the email message:
server_ssl.sendmail(user, recipient, message)
Close the connection:
server_ssl.close()
Here's an updated example using SMTP_SSL:
import smtplib def send_email(user, pwd, recipient, subject, body): # ... Same as before ... # Use SMTP_SSL instead of SMTP server_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465) server_ssl.ehlo() server_ssl.login(user, pwd) # ... Same as before ...
By using SMTP_SSL and port 465, you'll establish a secure connection and avoid the error "SMTP AUTH extension not supported by server."
The above is the detailed content of Why Does My Python Gmail Email Script Show 'SMTP AUTH Extension Not Supported,' and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!