Sending Emails with Gmail via Python
This article addresses the common issue encountered when attempting to send emails through Gmail using Python, resulting in the error "SMTP AUTH extension not supported by server." The Python script provided in the question demonstrates the process of setting up an email with Gmail as the provider.
To resolve the issue, it is crucial to enable Transport Layer Security (TLS), a secure communication protocol, before attempting to authenticate with Gmail's SMTP server. The following steps outline the necessary modifications:
server = smtplib.SMTP('smtp.gmail.com:587') server.starttls() server.login(username, password)
Alternative Method
If you encounter persistent issues with TLS, you can opt for Simple Mail Transfer Protocol with Secure Socket Layer (SMTP_SSL), which uses a secure port (465) for communication. To use SMTP_SSL, you will need to create an SMTP_SSL object:
server_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465) server_ssl.ehlo() server_ssl.login(gmail_user, gmail_pwd) server_ssl.sendmail(FROM, TO, message) server_ssl.close()
Remember to replace "gmail_user" with your Gmail address and "gmail_pwd" with your Gmail password. Once these changes are implemented, you should be able to successfully send emails through Gmail using Python.
The above is the detailed content of How Can I Fix 'SMTP AUTH extension not supported by server' Error When Sending Emails with Gmail via Python?. For more information, please follow other related articles on the PHP Chinese website!