Sending Mail Error With Python Smtplib
I am attempting to use the python 3.2 SMTPlib.sendmail() function to send a message, after some modifcation of the SMTP library (namely commenting out the rset() function which was
Solution 1:
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()
Solution 2:
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
Post a Comment for "Sending Mail Error With Python Smtplib"