Issue sending email with python?

python, smtp

Solution

You need to contact the gmail mail server on the submission port (587), not the default 25:

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

You also need to use `server.starttls()` before logging in (so that your password is not sent in the clear!). This is from a script I have and it works for me:

server = smtplib.SMTP()
server.connect("smtp.gmail.com", "submission")
server.starttls()
server.ehlo()
server.login(user, password)

Problem

I'm trying to make an email script in python. Here's what I have (from pythonlibrary.org): ``` #! /usr/bin/env python import smtplib import string SUBJECT = "An email!" TO = "me@icloud.com" FROM = "me@gmail.com" text = "This text is the contents of an email!" BODY = string.join(( "From: %s" % FROM, "To: %s" % TO, "Subject: %s" % SUBJECT , "", text ), "\r\n") server = smtplib.SMTP('smtp.gmail.com') server.login('me@gmail.com', 'mypassword') # Not very secure, I know, but this email is dedicated to this script server.sendmail(FROM, [TO], BODY) server.quit() ``` I get `smtplib.SMTPException: SMTP AUTH extension not supported by server.` Is this is so, then why does smtp.gmail.com respond at all? Is this a problem with Gmail, or my script, or something else? Error message: ``` Traceback (most recent call last): File "/Users/student/Desktop/mail.py", line 18, in <module> server.login('*******@gmail.com', '**************') File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 552, in login smtplib.SMTPException: SMTP AUTH extension not supported by server. ```

Original source