发送邮件错误python-> [Errno 11001] getaddrinfo失败

时间:2020-07-18 10:38:49

标签: python email gmail send

我不确定为什么会出现此错误:

代码:

import smtplib
from email.mime.text import MIMEText

me = 'so****@gmail.com'             
you = 'v****@gmail.com'         
contents = 'hi'   

msg = MIMEText(contents, _charset='euc-kr')
msg['Subject'] = 'hi'            
msg['From'] = me
msg['To'] = you


google_server = smtplib.SMTP_SSL('smtp.google.com', 465)
google_server.login('so****@gmail.com', '****')
google_server.sendmail('so****@gmail.com', ['v****@gmail.com'], msg.as_string())
google_serve.quit()

错误:

PS C:\Users\somin\Documents\python project> python .\hw01.py
Traceback (most recent call last):
  File ".\hw01.py", line 15, in <module>
    google_server = smtplib.SMTP_SSL('smtp.google.com', 465)
  File "C:\Users\somin\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 1034, in __init__
    SMTP.__init__(self, host, port, local_hostname, timeout,
  File "C:\Users\somin\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 253, in __init__
    (code, msg) = self.connect(host, port)
  File "C:\Users\somin\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "C:\Users\somin\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 1040, in _get_socket
    new_socket = socket.create_connection((host, port), timeout,
  File "C:\Users\somin\AppData\Local\Programs\Python\Python38\lib\socket.py", line 787, in create_connection     
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:\Users\somin\AppData\Local\Programs\Python\Python38\lib\socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

0 个答案:

没有答案