Sending mail error with python smtplib
The following works for microsoft, google, yahoo accounts on Python 2.7 and Python 3.2:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Send email via smtp_host."""
import smtplib
from email.mime.text import MIMEText
from email.header import Header
####smtp_host = 'smtp.live.com' # microsoft
####smtp_host = 'smtp.gmail.com' # google
smtp_host = 'smtp.mail.yahoo.com' # yahoo
login, password = ...
recipients_emails = [login]
msg = MIMEText('body…', 'plain', 'utf-8')
msg['Subject'] = Header('subject…', 'utf-8')
msg['From'] = login
msg['To'] = ", ".join(recipients_emails)
s = smtplib.SMTP(smtp_host, 587, timeout=10)
s.set_debuglevel(1)
try:
s.starttls()
s.login(login, password)
s.sendmail(msg['From'], recipients_emails, msg.as_string())
finally:
s.quit()
Add the following to your code before logging in and have a try again;
try:
self.smtp.ehlo()
self.smtp.starttls()
self.smtp.ehlo
except:
print "No TLS :("
#do login here