Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python sending email via Gmail failed

Tags:

python

gmail

I am using this piece of code:

import smtplib

fromaddr = '[email protected]'
toaddrs  = '[email protected]'
msg = 'There was a terrible error that occured and I wanted you to know!'


# Credentials (if needed)
username = 'myusername'
password = 'passwd'

# The actual mail send
server = smtplib.SMTP_SSL('smtp.gmail.com',465)
server.ehlo()
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

I am receiving this error:

Traceback (most recent call last): File "C:/Python34/sendemail.py", line 15, in server.starttls() File "C:\Python34\lib\smtplib.py", line 673, in starttls raise SMTPException("STARTTLS extension not supported by server.") smtplib.SMTPException: STARTTLS extension not supported by server.

When I do exculde server.starttls() I am receiving different error message about authentication. I have another price of code when I am accessing Gmail via web browser using webdriver and credentials works, so I copied and pasted to this code to make sure that credentials are correct.

I can't figure out why this is not working.

Thanks in advance.

like image 887
Dagged Avatar asked May 30 '26 00:05

Dagged


1 Answers

you'll have to see here as well

use port 587

server=smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
like image 69
Luke Avatar answered Jun 01 '26 14:06

Luke