2015-11-20 64 views
1

我把從燒瓶郵箱電子郵件,但自從嘗試使用在namecheap或BlueHost的郵件服務器中,我發現了以下錯誤:所以現在從Python中發送電子郵件扔SSLError「未知協議」

SSLError: [Errno 1] _ssl.c:510: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol 

我正在嘗試發送電子郵件,但沒有收到郵箱,但仍然收到同樣的錯誤。任何修復? 我的代碼如下:

from smtplib import SMTP 
smtp = SMTP() 

smtp.set_debuglevel(debuglevel) 
smtp.connect('xxxxxx', 26) 
smtp.login('[email protected]', 'xxxxxxx') 

from_addr = "xxx <[email protected]>" 
to_addr = [email protected] 

subj = "hello" 
date = datetime.datetime.now.strftime("%d/%m/%Y %H:%M") 

message_text = "Hello\nThis is a mail from your server\n\nBye\n" 

msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % (from_addr, to_addr, subj, date, message_text) 

smtp.sendmail(from_addr, to_addr, msg) 
smtp.quit() 

我的應用程序在Ubuntu 14.04運行在Amazon EC2上。

謝謝。

+0

smtpd服務是否在您選擇的計算機上運行? –

回答

3

這是給你這個錯誤的原因是因爲你的郵件服務器不是一個SMTP服務器。使用Gmail或其他smtp郵件服務發送郵件。嘗試通過服務器爲smtp.gmail.com並且端口爲587的gmail帳戶發送。首先,雖然您需要configure您的帳戶。