SSL Error while Sending Email with Python (Raspbian OS)

后端 未结 1 556
陌清茗
陌清茗 2021-01-23 06:57

I just write this code in Python under Raspbian OS:

import smtplib

fromaddr = \'*****@hotmail.de\'
toaddrs  = \'*****@hotmail.de\'
msg = \'Testmail\'

username          


        
相关标签:
1条回答
  • 2021-01-23 07:17

    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.

    0 讨论(0)
提交回复
热议问题