使用Python发送电子邮件时出现SSL错误(Raspbian OS) [英] SSL Error while Sending Email with Python (Raspbian OS)

查看:256
本文介绍了使用Python发送电子邮件时出现SSL错误(Raspbian OS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  import smtplib 

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

username ='** ***@hotmail.de'
password ='*****'

server = smtplib.SMTP('smtp.live.com',587)
服务器.ehlo()
server.starttls()
server.login(username,password)
server.sendmail(fromaddr,toaddrs,msg)
server.quit()

并获取以下错误消息:

  python ail.py 
追溯(最近的最后一次调用):
文件ail.py,第14行,< module>
server.login(username,password)
文件/usr/lib/python2.7/smtplib.py,第601行登录
AUTH_PLAIN ++ encode_plain(user,密码))
文件/usr/lib/python2.7/smtplib.py,第385行,docmd
return self.getreply()
文件/ usr / lib / python2 .7 / smtplib.py,第358行,在getreply
+ str(e))
smtplib.SMTPServerDisconnected:连接意外关闭:[Errno 1] _ssl.c:1359:
error :1408F10B:SSL例程:SSL3_GET_RECORD:错误版本号

我的错误是什么?可能有人帮我吗?



感谢

解决方案

已经签署了 http://live.com 并验证了我的帐户;你的代码在Ubuntu python 2.7和python3.3上工作:

 #!/ usr / bin / env python 
# - * - 编码:utf-8 - * -
通过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(recipient)

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

code> openssl 可以连接到它( ca-certificates 已安装,它不是这个bug ):

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

如果成功;您可以替换 smtplib.SMTP.starttls( )方法(在子类中)设置适当的ssl参数。


I just write this code in Python under Raspbian OS:

import smtplib

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

username = '*****@hotmail.de'
password = '*****'

server = smtplib.SMTP('smtp.live.com',587)
server.ehlo()
server.starttls()
server.login(username, password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

And get following Error-Message:

python ail.py
Traceback (most recent call last):
File "ail.py", line 14, in <module>
  server.login(username, password)
File "/usr/lib/python2.7/smtplib.py", line 601, in login
  AUTH_PLAIN + " " + encode_plain(user, password))
File "/usr/lib/python2.7/smtplib.py", line 385, in docmd
  return self.getreply()
File "/usr/lib/python2.7/smtplib.py", line 358, in getreply
  + str(e))
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [Errno 1] _ssl.c:1359: 
error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

What is my fault? Could somebody help me - please?

Regards

解决方案

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.

这篇关于使用Python发送电子邮件时出现SSL错误(Raspbian OS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆