해결된 질문
작성
·
25
0
ConnectionRefusedError: [WinError 10061] Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte
에러가 발생했는데 찾아보니
EMAIL_USE_TLS = False
EMAIL_USE_SSL = True
EMAIL_PORT = 465
위의 코드로도 시도를 해보라해서 해봤지만 계속 동일한 에러가 발생했습니다.
강의에서 사용된 운영체제는 맥 os이고 저는 윈도우 환경에서 실행했는데 윈도우환경에서 자주 발생하는 에러라고 하는데 해결방법을 찾기가 어려워서 문의남깁니다.
답변 2
0
안녕하세요, 인프런 AI 인턴입니다. 박명균님.
“ConnectionRefusedError: [WinError 10061]” 에러는 주로 네트워크 연결 문제로 인해 발생하는 오류입니다. 특히 이메일 서버에 연결할 때 잘못된 포트나 설정으로 인해 발생할 수 있는 문제입니다. 이 오류는 아래의 여러 가지 이유로 인해 발생할 수 있습니다:
포트 차단: Windows 방화벽 설정이나 보안 소프트웨어가 포트 465를 차단하고 있을 수 있습니다. 이 경우, 방화벽 설정을 확인하여 해당 포트를 열어주어야 합니다.
이메일 서버 설정 오류:
EMAIL_USE_TLS
와 EMAIL_USE_SSL
설정이 서버의 요구와 맞지 않을 수 있습니다. 두 옵션 중 하나만 True
로 설정해야 합니다. 이 경우 EMAIL_USE_SSL = True
가 적합합니다.SMTP 서버 주소 확인: SMTP 서버 주소가 올바르게 설정되어 있는지 확인해주세요. 일반적으로 EMAIL_HOST
를 설정하는 과정에서 오류가 발생할 수 있습니다.
서버의 지원 확인: 사용하는 이메일 서비스가 SSL이나 TLS 포트를 지원하는지, 그리고 어떤 포트를 사용해야 하는지 문서화된 자료를 참조하십시오.
유사한 문제에 대한 해결 방법을 논의한 기존 게시물을 추천해 드립니다. 아래 URL에서 관련된 질문과 해결책을 참고하실 수 있습니다:
문제가 계속된다면 추가적인 설정 값이나 오류 메시지를 공유해주시면 보다 구체적인 도움을 드릴 수 있습니다.
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.
In [2]: send_str_email("audrbs92@gmail.com")
---------------------------------------------------------------------------
ConnectionRefusedError Traceback (most recent call last)
Cell In[2], line 1
----> 1 send_str_email("audrbs92@gmail.com")
File ~\desktop\Privat\django_project\inflearn_coding\hands_on\utils.py:6, in send_str_email(email_to)
5 def send_str_email(email_to):
----> 6 send_mail(
7 "새로운 이메일 도착했습니다.",
8 "안녕하세요. Django에서 보낸 이메일입니다.",
9 settings.EMAIL_HOST_USER,
10 [email_to],
11 )
File ~\Desktop\Privat\django_project\inflearn_coding\hands_on\.venv\Lib\site-packages\django\core\mail\__init__.py:92, in send_mail(subject, message, from_email, recipient_list, fail_silently, auth_user, auth_password, connection, html_message)
89 if html_message:
90 mail.attach_alternative(html_message, "text/html")
---> 92 return mail.send()
File ~\Desktop\Privat\django_project\inflearn_coding\hands_on\.venv\Lib\site-packages\django\core\mail\message.py:307, in EmailMessage.send(self, fail_silently)
303 if not self.recipients():
304 # Don't bother creating the network connection if there's nobody to
305 # send to.
306 return 0
--> 307 return self.get_connection(fail_silently).send_messages([self])
File ~\Desktop\Privat\django_project\inflearn_coding\hands_on\.venv\Lib\site-packages\django\core\mail\backends\smtp.py:128, in EmailBackend.send_messages(self, email_messages)
126 return 0
127 with self._lock:
--> 128 new_conn_created = self.open()
129 if not self.connection or new_conn_created is None:
130 # We failed silently on open().
131 # Trying to send would be pointless.
132 return 0
File ~\Desktop\Privat\django_project\inflearn_coding\hands_on\.venv\Lib\site-packages\django\core\mail\backends\smtp.py:86, in EmailBackend.open(self)
84 connection_params["context"] = self.ssl_context
85 try:
---> 86 self.connection = self.connection_class(
87 self.host, self.port, **connection_params
88 )
90 # TLS/SSL are mutually exclusive, so only attempt TLS over
91 # non-secure connections.
92 if not self.use_ssl and self.use_tls:
File ~\AppData\Local\Programs\Python\Python313\Lib\smtplib.py:255, in SMTP.__init__(self, host, port, local_hostname, timeout, source_address)
252 self._auth_challenge_count = 0
254 if host:
--> 255 (code, msg) = self.connect(host, port)
256 if code != 220:
257 self.close()
File ~\AppData\Local\Programs\Python\Python313\Lib\smtplib.py:341, in SMTP.connect(self, host, port, source_address)
339 port = self.default_port
340 sys.audit("smtplib.connect", self, host, port)
--> 341 self.sock = self._get_socket(host, port, self.timeout)
342 self.file = None
343 (code, msg) = self.getreply()
File ~\AppData\Local\Programs\Python\Python313\Lib\smtplib.py:312, in SMTP._get_socket(self, host, port, timeout)
310 if self.debuglevel > 0:
311 self._print_debug('connect: to', (host, port), self.source_address)
--> 312 return socket.create_connection((host, port), timeout,
313 self.source_address)
File ~\AppData\Local\Programs\Python\Python313\Lib\socket.py:864, in create_connection(address, timeout, source_address, all_errors)
862 try:
863 if not all_errors:
--> 864 raise exceptions[0]
865 raise ExceptionGroup("create_connection failed", exceptions)
866 finally:
867 # Break explicitly a reference cycle
File ~\AppData\Local\Programs\Python\Python313\Lib\socket.py:849, in create_connection(address, timeout, source_address, all_errors)
847 if source_address:
848 sock.bind(source_address)
--> 849 sock.connect(sa)
850 # Break explicitly a reference cycle
851 exceptions.clear()
ConnectionRefusedError: [WinError 10061] Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte
전체 에러 올립니다
# EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
# EMAIL_HOST = "smtp.gmail.com"
# EMAIL_USE_TLS = False
# EMAIL_USE_SSL = True
# EMAIL_PORT = 465
# EMAIL_HOST_USER = "audrbs92@gmail.com" # 발신자 이메일 # EMAIL_HOST_PASSWORD = "앱 비밀번호" # App Password
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com" EMAIL_USE_TLS = True EMAIL_PORT = 587 EMAIL_HOST_USER = "audrbs92@gmail.com" # 발신자 이메일
EMAIL_HOST_PASSWORD = "앱 비밀번호" # App Password
이렇게 두가지 방법으로 시해했지만 모두 동일한 오류 발생했습니다