2017-04-26 8 views
0

전자 메일을 보내기 위해 Python의 smtplib 모듈을 사용하려고하지만 계속 TimeoutError을받습니다.smtplib을 사용하여 전자 메일을 보내려는 TimeoutError

import smtplib 

def send(): 
    try: 
     server = smtplib.SMTP('smtp.gmail.com', 587) 
     server.ehlo() 
     server.starttls() 
     server.login(email, password) # Email and password are already defined 
     print('Enter recipient: ') 
     recipient = input() 
     print('Enter subject:') 
     subject = input() + '\n' 
     print('Enter body:') 
     body = input() 
     server.sendmail(email, recipient, body) 
     server.quit() 

    except TimeoutError as e: 
     print (str(e)) 

이 코드는 접수에 : 당신이 사용할 수 Gmail 계정에서 옵션 '보안 수준이 낮은 앱 허용'하지 않은 것처럼

[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

+0

아마 연결 문제 또는 방화벽? – jpnkls

답변

1

것 같습니다. 여기에 공식적으로 구글에서 더 많은입니다

, https://support.google.com/accounts/answer/6010255?hl=en

+0

이미이 설정을 사용했지만 아직 연결하지 않았습니다. 내 타임 아웃 범위를 늘리려고한다면 생각 중입니다. import socket socket.setdefaulttimeout (120)이 방법이 가능합니까? – user7722705

+0

@ user7722705 : 그냥 물어 보지 마세요! – martineau