다음은 SMTP 서버에 연결하고 메일을 보내는 내 스크립트입니다.파이썬 스크립트를 사용하여 SMTP 서버에 연결할 수 없습니다.
from smtplib import SMTP
import datetime
debuglevel = 0
smtp = SMTP()
smtp.set_debuglevel(debuglevel)
smtp.connect('smtp.gmail.com', 26)
smtp.login('[email protected]', 'Pa***wd')
from_addr = "Ashwin<[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()
그러나 다음과 같은 오류가 발생합니다 : -
Traceback (most recent call last):
File "C:\Python33\Bidhoo.py", line 15, in <module>
smtp.connect('smtp.gmail.com', 26)
File "C:\Python33\lib\smtplib.py", line 317, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python33\lib\smtplib.py", line 288, in _get_socket
self.source_address)
File "C:\Python33\lib\socket.py", line 424, in create_connection
raise err
File "C:\Python33\lib\socket.py", line 415, in create_connection
sock.connect(sa)
TimeoutError: [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
이 오류의 근본 원인을 찾아 도와주세요. 또한 누구나 SMTP에 연결할 수있는 대체 코드를 공유 할 수 있습니다.
스택 오버플로에 오신 것을 환영합니다! 질문에 대한 더 나은 답변을 얻으려면 [질문하는 방법] (http://stackoverflow.com/questions/how-to-ask) 기사를 읽고 마음을 맡으십시오. –