Skip to content Skip to sidebar Skip to footer

Ssl Error While Sending Email With Python (raspbian Os)

I just write this code in Python under Raspbian OS: import smtplib fromaddr = '*****@hotmail.de' toaddrs = '*****@hotmail.de' msg = 'Testmail' username = '*****@hotmail.de' pass

Solution 1:

After I've signed in on http://live.com and validated my account; your code worked as is on Ubuntu python 2.7 and python3.3:

#!/usr/bin/env python# -*- coding: utf-8 -*-"""Send email via live.com."""import smtplib
from email.mime.text      import MIMEText
from email.header         import Header

login, password = ...

msg = MIMEText(u'body…', 'plain', 'utf-8')
msg['Subject'] = Header(u'subject…', 'utf-8')
msg['From'] = login
recipients = [login]
msg['To'] = ", ".join(recipients)

s = smtplib.SMTP('smtp.live.com', 587, timeout=10)  
s.set_debuglevel(1)
try:
    s.starttls() 
    s.login(login, password) 
    s.sendmail(msg['From'], recipients, msg.as_string())
finally:
    s.quit()

Check whether openssl can connect to it (ca-certificates is installed and it is not this bug):

$ openssl s_client -starttls smtp -connect smtp.live.com:587

If it is successful; you could replace smtplib.SMTP.starttls() method (in a subclass) to set appropriate ssl parameters.

Post a Comment for "Ssl Error While Sending Email With Python (raspbian Os)"