1

I am trying to send mail using python smtplib module, but I got error.

import smtplib
s = smtplib.SMTP('smtp.gmail.com', 587)
s.ehlo()
s.starttls()
s.login("xxxxxxxx@gmail.com", "yyyyyyy")
message = "Message_you_need_to_send"
s.sendmail("xxxxxxxxx@gmail.com", "aaaaaaaaa@gmail.com", message)
s.quit()

I got error like below:

Traceback (most recent call last): File "/home/engineer/demo.py", line 52, in s.starttls() File "/usr/lib/python2.7/smtplib.py", line 637, in starttls raise SMTPException("STARTTLS extension not supported by server.") SMTPException: STARTTLS extension not supported by server.

Star
  • 3,222
  • 5
  • 32
  • 48
venkat
  • 46
  • 1
  • 4

2 Answers2

0

I refer the solution from another link. You may try to remove s.ehlo() before s.starttls().

I tested your code with my own gmail account, it seems the code should work with s.echlo(). You may like to check your gmail security setting eg enable Less secure apps, Let less secure apps use your account

You also enable debug by using s.set_debuglevel(1)

import smtplib

s = smtplib.SMTP('smtp.gmail.com', 587)

s.set_debuglevel(1)

s.ehlo()

s.starttls()

Zhang Ran
  • 196
  • 2
  • 9
  • Log 1/2: send: 'ehlo [127.0.1.1]\r\n' reply: '250-smtp.gmail.com at your service, [115.118.5.146]\r\n' reply: '250-SIZE 35882577\r\n' reply: '250-8BITMIME\r\n' reply: '250-ENHANCEDSTATUSCODES\r\n' reply: '250-PIPELINING\r\n' reply: '250 SMTPUTF8\r\n' reply: retcode (250); Msg: smtp.gmail.com at your service, [115.118.5.146] SIZE 35882577 8BITMIME ENHANCEDSTATUSCODES PIPELINING SMTPUTF8 – venkat Dec 21 '17 at 05:11
  • Log 2/2: Traceback (most recent call last): File "/home/engineer/mail.py", line 8, in s.starttls() File "/usr/lib/python2.7/smtplib.py", line 637, in starttls raise SMTPException("STARTTLS extension not supported by server.") SMTPException: STARTTLS extension not supported by server. – venkat Dec 21 '17 at 05:11
  • what is the status of your **Allow less secure apps.** in your gmail setting? – Zhang Ran Dec 22 '17 at 05:33
  • Allow less secure apps :ON state – venkat Dec 22 '17 at 06:05
  • Was't require, issue was with the Firewall permissions at Office network – venkat Dec 27 '17 at 07:25
0

No changes as far as code is concerned, end up finding out, Issue was associated with enough firewall permissions.

venkat
  • 46
  • 1
  • 4