Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I'm attempting to send an email (Gmail) through python, however, I am getting the following error. 

Traceback (most recent call last):  

File "emailSend.py", line 14, in <module>  

server.login(username,password)  

File "/usr/lib/python2.5/smtplib.py", line 554, in login  

raise SMTPException("SMTP AUTH extension not supported by server.")  

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

Look at the below python script:

import smtplib

fromaddr = '[email protected]'

toaddrs  = '[email protected]'

msg = 'Why,Oh why!'

username = '[email protected]'

password = 'pwd'

server = smtplib.SMTP('smtp.gmail.com:587')

server.starttls()

server.login(username,password)

server.sendmail(fromaddr, toaddrs, msg)

server.quit()

1 Answer

0 votes
by (26.4k points)

You want to just say EHLO before running straight into STARTTLS

server = smtplib.SMTP('smtp.gmail.com:587')

server.ehlo()

server.starttls()

Additionally, you should make From:, To: and Subject: message headers, isolated from the message body by a clear line and use CRLF as EOL markers. 

Example:

msg = "\r\n".join([

  "From: [email protected]",

  "To: [email protected]",

  "Subject: Just a message",

  "",

  "Why, oh why"

  ])

Note:

With the goal for this to work you want to enable the "allow less secure applications" choice in your Gmail account configuration. Else you will get a "basic security alert" when Gmail identifies that a non-Google application is attempting to login to your account.

Interested to learn the concepts of Python in detail? Come and join the python course to gain more knowledge in Python

Watch this below video tutorial for more information

Related questions

Browse Categories

...