Aug-12-2019, 02:38 PM
I am stumped with trying to use the Python smtplib module. I have followed the instructions via https://pymotw.com/2/smtplib/. I am using the example from the second part "Authentication and Encryption":
Barry
Python 2.7.13 on Win32
import smtplib
import email.utils
from email.mime.text import MIMEText
import getpass
# Prompt the user for connection info
to_email = raw_input('Recipient: ')
servername = raw_input('Mail server name: ')
username = raw_input('Mail user name: ')
password = getpass.getpass("%s's password: " % username)
# Create the message
msg = MIMEText('Test message from PyMOTW.')
msg.set_unixfrom('author')
msg['To'] = email.utils.formataddr(('Recipient', to_email))
msg['From'] = email.utils.formataddr(('Author', '[email protected]'))
msg['Subject'] = 'Test from PyMOTW'
server = smtplib.SMTP(servername)
try:
server.set_debuglevel(True)
# identify ourselves, prompting server for supported features
server.ehlo()
# If we can encrypt this session, do it
if server.has_extn('STARTTLS'):
server.starttls()
server.ehlo() # re-identify ourselves over TLS connection
server.login(username, password)
server.sendmail('[email protected]', [to_email], msg.as_string())
finally:
server.quit()But, I only get so far:Recipient: [email protected] Mail server name: smtpauth.isp.net Mail user name: [email protected] [email protected]'s password: send: 'ehlo 70WLKG105279.houtx.lcl\r\n' reply: '250-smtp.gmail.com at your service, [50.58.210.12]\r\n' reply: '250-SIZE 35882577\r\n' reply: '250-8BITMIME\r\n' reply: '250-STARTTLS\r\n' reply: '250-ENHANCEDSTATUSCODES\r\n' reply: '250-PIPELINING\r\n' reply: '250-CHUNKING\r\n' reply: '250 SMTPUTF8\r\n' reply: retcode (250); Msg: smtp.gmail.com at your service, [50.58.210.12] SIZE 35882577 8BITMIME STARTTLS ENHANCEDSTATUSCODES PIPELINING CHUNKING SMTPUTF8 send: 'STARTTLS\r\n' reply: '220 2.0.0 Ready to start TLS\r\n' reply: retcode (220); Msg: 2.0.0 Ready to start TLSAny suggestions would be much appreciated.
Barry
Python 2.7.13 on Win32
